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

Vue song progress bar sample code

Note that this is not a project created by vue-cl...

How to modify the "Browse" button of the html form to upload files

Copy code The code is as follows: <!DOCTYPE HT...

JavaScript implements mouse control of free moving window

This article shares the specific code of JavaScri...

Detailed explanation of MySQL transaction processing usage and example code

MySQL transaction support is not bound to the MyS...

JavaScript Basics: Scope

Table of contents Scope Global Scope Function Sco...

Summary and practice of javascript prototype chain diagram

Table of contents Prototype chain We can implemen...

mysql 5.7.17 winx64.zip installation and configuration method graphic tutorial

Preface: I reinstalled win10 and organized the fi...

MySQL concurrency control principle knowledge points

Mysql is a mainstream open source relational data...

How to split and merge multiple values ​​in a single field in MySQL

Multiple values ​​combined display Now we have th...

How to simulate enumeration with JS

Preface In current JavaScript, there is no concep...

MySQL master-slave replication principle and practice detailed explanation

Table of contents Introduction effect principle f...