Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the root of the page garbled problem?

Shulou Source: shulou.com Published: 2022-06-03 06:57:29 11月15日 Update

This article mainly explains "what is the root of the page garbled problem". The content in the article is simple and clear, and it is easy to learn and understand. let's go deep into the editor's train of thought. Let's study and learn "what is the root of the page garbled problem"!

First, close default_charset in the PHP configuration file php.ini:

1. Page does not specify charset, Apache configuration defaultcharst gbk, page file encoding is utf-8

Result: garbled code. Use wireshark to grab the packet and find that the header returned by the server indicates:

The copy code is as follows:

Content-Type:text/html;charset=GB

Conclusion: when the page does not specify charset, the defaultcharset of Apache works

two。 The page specifies charset as utf-8, and Apache configures defaultcharset gbk. The page file is utf-8

The copy code is as follows:

Test Apache DefaultCharset

As a result, there is still garbled code.

Conclusion: when Apache is configured with DefaultCharset, the charset declaration of the page will be ignored.

3. PHP header declares that charset is utf8, Apache configures defaultcharst gbk, and the page file encoding is utf8

The copy code is 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.

Flipped through Apache2's manual:

AddDefaultCharset instruction

Indicates the default character set added to the HTTP reply header when the reply content is text/plain or text/html

Syntax AddDefaultCharsetOn | Off | charset

Default value AddDefaultCharsetOff

Scope serverconfig,virtualhost,directory,.htaccess

Override item FileInfo

State Core (C)

Module core

This instruction will be added to the HTTP reply header when and only if the reply content is text/plain or text/html

The default character set. In theory, this will overwrite the character set specified by tagging in the document body, but in practice

Usually depends on the settings of the user's browser. AddDefaultCharsetOff will disable this feature.

AddDefaultCharsetOn enables the default character set iso-8859-1 within Apache. You

You can also specify another charset in the name of the character set registered with IANA.

For example:

AddDefaultCharsetutf-8

That is, when Apache does not specify defaultcharset, the page encoding is specified by the page's own meta tag.

When Apache is specified, the encoding specified by the meta tag in the page is ignored. But allow the script to be directly header encoded to the client.

Thank you for your reading, the above is the content of "what is the root of the page garbled problem". After the study of this article, I believe you have a deeper understanding of what is the root cause of the page garbled problem. the specific use of the situation also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Page garbled code problem character character set encoding configuration source content file result time learning function instruction tag conclusion utf-8 plus Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple macOS NVidia Linux