I also had garbled code on my page today, so I looked up related problems online. It seems that this method is pretty good. I have tried it. I used the editp editor, just use the document - file encoding - change file encoding - select the encoding you need in the document - select the code you need
On web pages, the problem of Chinese garbled code often occurs. When I encountered garbled code problems in the past, I 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 the html file, and the following pictures will be explained.
Test 1:
Save html files in UTF-8. See the following figure for the specific file content:
As you can see in the figure, the encoding method of the file is UTF-8, and the other in the red box below is set in eclipse. The red box above the picture indicates how the browser opens the file, which can be seen as UTF-8.
Use IE to open the file and you can see the following picture:
By checking the encoding method of the browser, you can see that the browser automatically selected the UTF-8 method and there was no garbled code.
Switch the encoding method of the browser to GB2312, you can see the following picture:
Test 2:
Save the html file in UTF-8 and set the encoding method in the file header to GBK, as shown in the figure below:
This shows that the encoding method of the file is UTF-8, and the default file opening method is GBK.
Screenshots of using IE to open this file are as follows:
You can see that the browser opens it in GB2312 according to the instructions of the html file. Since the encoding method of the file itself is UTF-8, garbled code appears. But the web page source file is not garbled.
If you choose the encoding method of the browser to be UTF-8, you can see the garbled code disappear. The screenshot is as follows:
At this point, the test is over. To summarize the following points:
1.html file has an encoded format, which can only be seen in a specific editor and set.
2. The charset set in the content-type at the head of the html file tells the browser how to open the file.
3. Generally, the encoding methods in points 1 and 2 should be consistent, and garbled code may occur if there is inconsistent.
4. If the browser displays garbled code, but the page source file is not garbled code, 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 the browser's encoding method.