Today a simple look at PHP, server, browser How to set the encoding
1.php
In PHP configuration file php.ini, you can set the character encoding
; PHP 's default character set is set to empty; Http://php.net/default-charsetdefault_charset = "gb2312"
In PHP 5.6 and Beyond, "UTF-8" is the default (before 5.6 is a null value), for the following functions: Htmlentities (), Html_entity_decode () and Htmlspecialchars (), If their encoding parameters are omitted, then the value of Default_charset is used for the default encoding of these functions. For iconv functions, if their arguments input_encoding 3.output_encoding/internal_ Encoding, if not set, will also take the value of default_charset, for mbstring function, if Mbstring.http_input mbstring.http_output Mbstring.internal_ If encoding is not set, it will also take the Default_charset value,
In addition, it is not recommended to set Default_charset to a null value. (Setting default_charset to a empty value is not recommended).
The encoding type of the script must be consistent with default_charset, otherwise it will be garbled.
2. The server, such as Apache, will refer to the PHP.ini setting when returning the response header Content-type.
Like what:
// php.ini in default_charset = "AAABBCCC"
View response header: content-type:text/html; Charset=aaabbccc
If the header function is used in a PHP script, the server's response header will follow the header function's settings.
3. About meta settings in the corresponding entity Content-type
< Head > < charset= "UTF-8"> <title> Document</title></head>
Its priority is lower than the content-type specified in the response header, that is, the encoding type is specified in the response header, and the browser follows the settings of the response header (typically, the final decision is in the browser's hands)
4. Browser encoding settings
Compared to the Chrome,ff,360 browser, IE8, found that Chrome browser seems to ignore the user's manual settings, the specific mechanism does not understand, and other browsers, as long as the user has changed the encoding, will be encoded according to user-specified decoding
From PHP script to browser, the analysis of encoding method