How to set encoding in php header

藏色散人
Release: 2023-03-04 12:18:02
Original
2118 people have browsed it

The syntax for php header setting encoding is "header("content-type:text/html; charset=xxx");", where the parameter charset represents the specific encoding format.

How to set encoding in php header

Recommended: "PHP Video Tutorial"

php header to define a php page as utf encoding or GBK Encoding

php页面为utf编码
header("Content-type: text/html; charset=utf-8");
php页面为gbk编码
header("Content-type: text/html; charset=gb2312");
php页面为big5编码
header("Content-type: text/html; charset=big5");
Copy after login

Usually the above code is placed on the homepage of the php page

header("content-type:text/html; charset=xxx");

The function of this function header() is to send the information in the brackets to the http header.

If the content in the brackets is as mentioned in the article, the function is basically the same as the tag. If you compare it with the first one, you will find that the characters are similar. But the difference is that if there is this function, the browser will always use the xxx encoding you requested and will never be disobedient, so this function is very useful. Why is this so? Then we have to talk about the difference between HTTPS headers and HTML information:

The https header is a string sent by the server before transmitting HTML information to the browser using the HTTP protocol.

Because the meta tag belongs to html information, the content sent by header() reaches the browser first. The popular point is that header() has a higher priority than meta (I don’t know if this can be said). Add a php page that has both header("content-type:text/html; charset=xxx") and , the browser will only recognize the former http header and not the meta. Of course, this function can only be used within php pages.

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

Related labels:
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