Four common garbled HTML web page problems and their solutions

PHP中文网
Release: 2017-06-06 11:47:31
Original
2018 people have browsed it

Four common html webpage garbled problems and solutions, html garbled code

Last week when my colleague was working on a webpage, he encountered that the webpage was garbled when he opened it. The colleague was very confused and didn’t know how to solve it. Below, the editor takes the time to sort out and share with you the more common garbled HTML web page problems and their solutions.

In fact, there are several main reasons for garbled web pages. The solutions are given below.

1. HTML character encoding problem

This problem is more common, and it is also the most obvious and easiest to solve. .

Add:

<meta http-equiv="Content-Type" Content="text/html;charset=utf8"/>
Copy after login

in the of the web page.

2. PHP character encoding problem

This is similar to the above.

Add:

header("Content-type:text/html;charset=utf8");
Copy after login

above the file.

3. The encoding of the file itself

Not only is our content encoded, but the file itself is also encoded.

Use Notepad++ to open a file and you can see the content displayed in the lower right corner.

is the encoding of the file itself.

You can use "Format" on the Notepad++ toolbar to convert the encoding for our files.

4. Database encoding issues

MySQL data is latin1 encoded when installed by default, so it is likely to cause garbled web pages without paying attention.

Use root to enter the database,

输入show variables like &#39;character%&#39;
Copy after login

can see the 7 values ​​of

character_set_client 
character_set_connection
character_set_database
character_set_filesystem
character_set_results
character_set_server
character_set_system
Copy after login

.

Among them, the set names ut8 command can set the three

character_set_client 
character_set_connection
character_set_results
Copy after login

to utf8.

So when creating a MySQL database, be sure to set the character set and collation to utf8.

In the file connecting to the database, perform mysql_query("SET NAMES UTF8") on the database.

can basically guarantee that the web page will not have garbled code problems.

The above are four common html web page garbled problems and solutions that the editor has shared with you. I hope you like them.

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
Popular Tutorials
More>
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!