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

May 16, 2016 pm 04:40 PM
Chinese garbled

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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Methods to solve the problem of Chinese garbled characters in PHP Dompdf Methods to solve the problem of Chinese garbled characters in PHP Dompdf Mar 05, 2024 pm 03:45 PM

Methods to solve the Chinese garbled problem of PHPDompdf PHPDompdf is a tool for converting HTML documents to PDF files. It is powerful and easy to use. However, when processing Chinese content, you sometimes encounter the problem of garbled Chinese characters. This article will introduce some methods to solve the Chinese garbled problem of PHPDompdf and provide specific code examples. 1. When using font files to process Chinese content, a common problem is that Dompdf does not support Chinese content by default.

The ultimate solution to the problem of Chinese garbled characters in PyCharm The ultimate solution to the problem of Chinese garbled characters in PyCharm Jan 27, 2024 am 08:00 AM

The ultimate method to solve the problem of Chinese garbled characters in PyCharm requires specific code examples. Introduction: PyCharm, as a commonly used Python integrated development environment (IDE), has powerful functions and a friendly user interface, and is loved and used by the majority of developers. However, when PyCharm processes Chinese characters, it may sometimes encounter garbled characters, which causes certain problems in development and debugging. This article will introduce how to solve the Chinese garbled problem in PyCharm and give specific code examples. 1. Set up the project

Common causes and solutions for Chinese garbled characters in MySQL installation Common causes and solutions for Chinese garbled characters in MySQL installation Mar 02, 2024 am 09:00 AM

Common reasons and solutions for Chinese garbled characters in MySQL installation MySQL is a commonly used relational database management system, but you may encounter the problem of Chinese garbled characters during use, which brings trouble to developers and system administrators. The problem of Chinese garbled characters is mainly caused by incorrect character set settings, inconsistent character sets between the database server and the client, etc. This article will introduce in detail the common causes and solutions of Chinese garbled characters in MySQL installation to help everyone better solve this problem. 1. Common reasons: character set setting

What to do if ajax transmits Chinese garbled characters What to do if ajax transmits Chinese garbled characters Nov 15, 2023 am 10:42 AM

Solutions for ajax to transmit Chinese garbled characters: 1. Set a unified encoding method; 2. Server-side encoding; 3. Client-side decoding; 4. Set HTTP response headers; 5. Use JSON format. Detailed introduction: 1. Set a unified encoding method to ensure that the server and client use the same encoding method. Under normal circumstances, UTF-8 is a commonly used encoding method because it can support multiple languages ​​​​and character sets; 2 , Server-side encoding. On the server side, ensure that the Chinese data is encoded in the correct encoding method and then passed to the client, etc.

What should I do if the PHP web page has Chinese garbled characters? A complete solution What should I do if the PHP web page has Chinese garbled characters? A complete solution Mar 26, 2024 pm 03:27 PM

The problem of Chinese garbled characters in PHP web pages is that Chinese characters are displayed as garbled characters in the web page display. This situation is usually caused by inconsistent encoding or the character set is not set. Solving the problem of Chinese garbled characters in PHP web pages requires starting from many aspects. The following are some common solutions and specific code examples. Set the PHP file encoding: First make sure that the encoding of the PHP file itself is UTF-8. You can set the UTF-8 encoding when saving in the editor, or add the following code to the header of the PHP file to set the encoding: &l

A practical method to effectively solve the problem of Chinese garbled characters in Eclipse A practical method to effectively solve the problem of Chinese garbled characters in Eclipse Jan 03, 2024 pm 05:50 PM

Practical tips for quickly solving Chinese garbled characters in Eclipse require specific code examples. Overview: Eclipse is a widely used integrated development environment (IDE) that not only supports the development of multiple programming languages, but also supports multiple operating systems. However, sometimes when using Eclipse, we may encounter the problem of Chinese garbled characters, which brings inconvenience to our development work. This article will introduce some practical techniques to help us quickly solve the problem of Chinese garbled characters in Eclipse, and attach specific code examples. one,

Methods to solve the problem of Chinese garbled characters in Linux system Methods to solve the problem of Chinese garbled characters in Linux system Feb 19, 2024 am 09:22 AM

The problem of Linux Chinese garbled characters is a problem that many Chinese users often encounter when using Linux systems. The main reason for garbled Chinese characters is that the default character encoding used by the Linux system is UTF-8, but some software or applications may not be compatible with UTF-8 encoding, causing Chinese characters to not be displayed correctly. There are many ways to solve this problem. Several common solutions will be detailed below and specific code examples will be provided. Modify the terminal character encoding settings: The terminal character encoding settings determine whether the terminal can correctly

Effective method to solve matplotlib Chinese garbled problem Effective method to solve matplotlib Chinese garbled problem Jan 13, 2024 am 11:03 AM

An effective method to quickly solve matplotlib Chinese garbled characters. Introduction: matplotlib is a commonly used drawing library in Python. However, when using Chinese for annotation and display, garbled characters often occur. This article will introduce some effective workarounds and provide specific code examples. 1. Set the font. matplotlib uses system fonts for Chinese display by default. However, system fonts often do not contain Chinese characters, so you need to manually set the appropriate Chinese font. First, you need to confirm whether the computer has

See all articles