First, close the default_charset in PHP config file php.ini:
1. Page does not specify CharSet, Apache configuration defaultcharst GBK, page file encoding is Utf-8
Result: garbled, using Wireshark to grab the packet, found that the server returned the header indicated in:
Copy CodeThe code is as follows:
Content-type:text/html;charset=gb
Conclusion: Apache Defaultcharset works when the page does not indicate CharSet
2. The page specifies charset for utf-8, Apache configuration Defaultcharset GBK. Page file is Utf-8
Copy the Code code as follows:
Test Apache Defaultcharset
The result is still garbled.
Conclusion: When Apache is configured with Defaultcharset, the CharSet declaration of the page is ignored.
3. PHP Header declaration charset for UTF8, Apache configuration defaultcharst GBK, page file encoding is UTF8
Copy the Code code as follows:
Header ("content-type:text/html; Charset=utf-8 ");
Result: the page appears normal.
4 Apache set Defaultcharset off
As a result, the page appears normal.
Scroll through the following Apache2 's Handbook:
Adddefaultcharset directive
Describes the default character set that is added to the HTTP reply header when the answer is Text/plain or text/html
Grammar adddefaultcharseton| Off|charset
Default Value Adddefaultcharsetoff
Scope serverconfig,virtualhost,directory,.htaccess
Overwrite Item FileInfo
State Core (C)
Module Core
This instruction will be added to the HTTP reply header when and only if the answer is Text/plain or text/html
The default character set. Theoretically this will overwrite the character set specified by the tag in the body of the document , but the actual
Behavior usually depends on the settings of the user's browser. Adddefaultcharsetoff This feature will be disabled.
Adddefaultcharseton will enable the default character set iso-8859-1 inside Apache. You
You can also specify the use of another charset in the name of a character set registered with the IANA.
For example:
AddDefaultCharsetutf-8
In other words, when Apache does not specify Defaultcharset, the page encoding is specified by the page's own meta tag.
When Apache specifies, the encoding specified by the META tag in the page is ignored. But allow the script to direct the header encoding to the client
Finally, there is one more question that does not produce the result:
What if Apache and the page are not specified?
I am on my own machine, if not specified, the default is UTF8.