Home > Web Front-end > HTML Tutorial > The Chinese garbled problem of html files and the display problem in the browser_HTML/Xhtml_Web page production

The Chinese garbled problem of html files and the display problem in the browser_HTML/Xhtml_Web page production

WBOY
Release: 2016-05-16 16:40:20
Original
1942 people have browsed it

My page today also had garbled characters, so I searched for related issues on the Internet. It seems that this method is quite good. I also tried it. I used the editp editor and went to Document - File Encoding - Change the file encoding—just choose the encoding you need

In web pages, the problem of Chinese garbled characters often occurs. When I encountered garbled code problems in the past, I just kept trying different encoding methods until I succeeded. Yesterday, the project encountered this problem again, so I did a simple test.

HTML files have encoding methods, such as "UTF-8", "GBK", etc. These may not be visible in Notepad, but in eclipse, you can set the encoding method of html files, as explained in the following pictures.

Test 1:

Save the html file in "UTF-8" mode. The specific file content is shown below:

As you can see in the picture, the encoding method of the file is "UTF-8", as shown by Other in the red box below, which is set in eclipse. The red box above the picture indicates the encoding method used by the browser to open the file, which can be seen as "UTF-8".

Use IE to open the file and you will see the following picture:

Check the encoding method of the browser. You can see that the browser automatically selects the "UTF-8" method and no garbled characters appear.

Switch the browser encoding method to "GB2312", you can see the following picture:

Test 2:

Save the html file in "UTF-8" mode, and set the encoding method in the file header to "GBK", as shown below:

This shows that: the encoding method of the file is "UTF-8", and the default file opening method is "GBK".

The screenshot of opening this file using IE is as follows:

You can see that the browser opens it in "GB2312" mode according to the instructions of the html file. Because the encoding method of the file itself is "UTF-8", garbled characters appear. But the source file of the web page is not garbled.

Select the browser encoding method as "UTF-8" and you can see that the garbled characters disappear. The screenshot is as follows:

At this point, the test is over. Summarize the following points:

1. The html file has an encoding format, which can only be seen and set in a specific editor.

2. The "charset" set in the "content-type" in the header of the html file tells the browser the encoding method used to open the file.

3. Generally, the encoding methods in points 1 and 2 should be consistent. Inconsistency may result in garbled characters.

 4. If the browser displays garbled characters, but the page source file is not garbled, you can see the correct Chinese by modifying the browser's encoding method. If the correct "charset" is set in the source file, there is no need to modify it. The browser's encoding method.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template