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

How to set gbk encoding in php?

青灯夜游
Release: 2023-03-05 08:06:01
Original
4094 people have browsed it

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 <meta http-equiv to the static page ="Content-Type" content="text/html; charset=gb2312">, 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 #, the encoding format of all files is utf-8.

header() declares content-type

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

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
Copy after login

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
    , 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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template