Home >Web Front-end >HTML Tutorial >Reasons and solutions for garbled html web pages

Reasons and solutions for garbled html web pages

王林
王林Original
2019-08-15 14:52:1428684browse

Foreword: When using HTML CSS for web page layout, various garbled problems often occur when browsing web pages. So if we need to solve this problem, we need to first understand the cause of the problem. This article will analyze the various causes and solutions for everyone. Everyone is welcome to comment below, thank you!

Recommended video tutorial: HTML tutorial

Cause of garbled characters

1, If the source code of the web page is written by gbk, and the text in the content is utf-8, then, open it at this time HTML garbled characters will appear in the browser. On the contrary, garbled characters will also appear.

2, the HTML webpage encoding is gbk, but the program calls out the content encoded in utf-8 from the program library. It will cause garbled encoding.

3. The browser cannot automatically detect the encoding of the web page, causing the web page to be garbled.

Reasons and solutions for garbled html web pages

2. Methods to solve garbled characters

The first: HTML web page source code encoding and Chinese characters The input encoding is different.

Solution: Use professional editing software to write HTML web pages. For example DW.Try not to use Notepad directly for writing.

Second : The web page setting encoding is gbk, but the database storage data encoding format is UTF-8. At this time, the program queries The database data display data can be transcoded.

For example:

mysql_query("SET NAMES 'UTF-8'") //将查询数据转码为UTF-8

Then don’t forget the following content when making a web page:

<meta http-equiv="Content-Type" content="text/html"; charset="utf-8" />

Reasons and solutions for garbled html web pages

Third Category: The browser causes garbled characters

This reason is generally caused by the web page not setting the meta charset encoding. As a result, the browser cannot recognize the default encoding type of your web page.

Solution:

1. If the web page is garbled when browsing in the browser, find the menu to convert the encoding in the browser.

2. If you develop your own web page, you must add the meta charset encoding tag to the web page.

<meta http-equiv="Content-Type" content="text/html";charset="UTF-8" />

If the conversion is done without editing the meta charset encoding tag in Notepad, which will also cause garbled characters, it is because directly adding or adding in Notepad After the encoding format is modified, the corresponding HTML hypertext document content does not change with the addition or modification of the encoding format. At this time, true transcoding is required, so it is best to use professional development software to write the code.

More HTML practical tutorials: HTML practical tutorial

The above is the detailed content of Reasons and solutions for garbled html web pages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:What does checked mean?Next article:What does checked mean?