The root of page garbled problem and its analysis _php

Source: Internet
Author: User
Keywords Page garbled
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:

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:

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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.