Home >Backend Development >PHP Problem >How to set gbk encoding in php?

How to set gbk encoding in php?

青灯夜游
青灯夜游Original
2020-08-25 10:59:254122browse

php method to set gbk encoding: In the head of the PHP file, add the "header("Content-type: text/html; charset=gb2312");" code to declare the content-type and define the web page Encode to gbk encoding and save it.

How to set gbk encoding in php?

Recommended: "PHP Video Tutorial"

php set gbk encoding

If you want to use gbk encoding, then php should output the header: header("Content-Type: text/html; charset=gb2312"), add 387ddc5f9a52da5113ec00c23b62286d, the encoding format of all files is ANSI, you can open it with Notepad, save as, select the encoding as ANSI, and overwrite the source file.

If you want to use utf-8 encoding, then php should output the header: header("Content-Type: text/html; charset=utf-8"), add ## to the static page #3dac93479e15392607bc2263a9a9421e, the encoding format of all files is utf-8.

header() declares content-type

header(“Content-Type: text/html; charset=gb2312")

Content-Type (content type), generally refers to the Content-Type that exists in the web page, used for Defining the type of network file and the encoding of the web page determines the form and encoding in which the browser will read the file. This is why we often see that the result of clicking on some PHP web pages is to download a file or a picture.

The Content-Type header tells the client the content type of the actual content returned.

Grammar format:

Content-Type: text/html; charset=utf-8
Content-Type: multipart/form-data; boundary=something

Example:

Common media format types are as follows:

  • text/html: HTML format

  • text/plain: plain text format

  • text/xml: XML format

  • image/ gif: gif image format

  • image/jpeg: jpg image format

  • image/png: png image format

Media format type starting with application:

  • application/xhtml xml: XHTML format

  • ##application/xml: XML data Format
  • application/atom xml: Atom XML aggregation format
  • application/json: JSON data format
  • application/pdf:pdf format
  • ##application/msword:Word document format
  • application/octet-stream:binary stream data ( Such as common file downloads)
  • application/x-www-form-urlencoded: The default encType in 021c3b663bc40c51800146aa2ebefcab, form form data is encoded as key/ The value format is sent to the server (the default format for submitting data in the form)
  • Another common media format is used when uploading files:

multipart/form-data: When you need to upload files in a form, you need to use this format
  • Related learning recommendations:
PHP programming from entry to proficient

The above is the detailed content of How to set gbk encoding in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn