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 explanation of how a SQL statement is executed in MySQL

Overview I have recently started learning MySQL r...

About scroll bar in HTML/removing scroll bar

1. The color of the scroll bar under xhtml In the ...

Practical basic Linux sed command example code

The Linux stream editor is a useful way to run sc...

How to install mysql5.7.24 binary version on Centos 7 and how to solve it

MySQL binary installation method Download mysql h...

Uniapp WeChat applet: Solution to key failure

uniapp code <template> <view> <ima...

How to change the Ali source in Ubuntu 20.04

Note that this article does not simply teach you ...

A few experiences in self-cultivation of artists

As the company's influence grows and its prod...

JavaScript to achieve custom scroll bar effect

In actual projects, the up and down scroll bars a...

Detailed steps to install the NERDTree plugin in Vim on Ubuntu

NERDTree is a file system browser for Vim. With t...

How to fill items in columns in CSS Grid Layout

Suppose we have n items and we have to sort these...

Pure CSS3 realizes the effect of div entering and exiting in order

This article mainly introduces the effect of div ...

React Native environment installation process

react-native installation process 1.npx react-nat...

Solution to the problem of installing MySQL compressed version zip

There was a problem when installing the compresse...

Implementation of JavaScript downloading linked images and uploading them

Since we are going to upload pictures, the first ...

A brief discussion on the principle of React two-way data binding

Table of contents What is two-way data binding Im...