The Chinese garbled characters in HTML files and the display problems in browsers

The Chinese garbled characters in HTML files and the display problems in browsers

My page today also had garbled characters, so I searched for related problems on the Internet. It seems that this method is quite good. I also tried it. I used the editp editor. In Document-File Encoding-Change File Encoding-Select the encoding you need.

On web pages, the problem of garbled Chinese characters often occurs. When I encountered garbled characters in the past, I would keep trying different encoding methods until I succeeded. The project encountered this problem again yesterday, so I did a simple test.

HTML files have encoding methods, such as "UTF-8", "GBK" and so on. These may not be visible in Notepad, but in Eclipse, you can set the encoding method of the HTML file, which will be explained in the following picture.

Test 1:

Save the html file in "UTF-8" mode. See the figure below for the specific file content:

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

Open the file using IE and you can see the following image:

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

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

Test 2:

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

This indicates that the file encoding 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. Since the file itself is encoded in "UTF-8", garbled characters appear. But the source file of the web page is not garbled.

Select "UTF-8" as the encoding method of the browser, and you can see that the garbled characters disappear. The screenshots are as follows:

This concludes the test. Summarize the following points:

1. HTML files have 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 to use when opening the file.

3. Generally, the encoding methods in points 1 and 2 should be consistent. If they are inconsistent, garbled characters may appear.

4. If garbled characters are displayed in the browser, but the source file of the page is not garbled, you can see the correct Chinese by changing the encoding method of the browser. If the correct "charset" is set in the source file, there is no need to change the encoding method of the browser.

<<:  Javascript destructuring assignment details

>>:  Solve the problem of Navicat for Mysql connection error 1251 (connection failed)

Recommend

Detailed installation and uninstallation tutorial for MySQL 8.0.12

1. Installation steps for MySQL 8.0.12 version. 1...

Example code of Vue3 encapsulated magnifying glass component

Table of contents Component Infrastructure Purpos...

HTML basics summary recommendation (paragraph)

HTML Paragraph Paragraphs are defined by the <...

Tutorial on installing mysql5.7.18 on windows10

This tutorial shares the installation and configu...

MySQL 5.7.17 winx64 installation and configuration tutorial

Today I installed the MySQL database on my comput...

Detailed explanation of Docker basic network configuration

External Access Randomly map ports Using the -P f...

Detailed explanation of the execution order of JavaScript Alert function

Table of contents question analyze solve Replace ...

Docker container orchestration implementation process analysis

In actual development or production environments,...

Detailed explanation of JavaScript function this pointing problem

Table of contents 1. The direction of this in the...

Steps to install RocketMQ instance on Linux

1. Install JDK 1.1 Check whether the current virt...

A record of the pitfalls of the WeChat applet component life cycle

The component lifecycle is usually where our busi...

MySQL download and installation details graphic tutorial

1. To download the MySQL database, visit the offi...

Java uses Apache.POI to export HSSFWorkbook to Excel

Use HSSFWorkbook in Apache.POI to export to Excel...