Home  >  Article  >  Backend Development  >  How to set encoding in php header

How to set encoding in php header

藏色散人
藏色散人Original
2020-08-13 10:41:592037browse

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");

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 3f2ae36b77c0b1762e465ca019e7bd30 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 1dd9d9bc813bb1594796bd2b8615c022 , 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!

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