Reasons and solutions for garbled html web pages

王林
Release: 2019-08-17 11:32:13
Original
28537 people have browsed it

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 bygbk, and the text in the content isutf-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 isgbk, but the program calls out the content encoded inutf-8from 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 exampleDW.Try not to use Notepad directly for writing.

Second: The web page setting encoding isgbk, but the database storage data encoding format isUTF-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
Copy after login

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

Copy after login

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 themeta charsetencoding. 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 themeta charsetencoding tag to the web page.

Copy after login

If the conversion is done without editing themetacharsetencoding 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!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!