Home  >  Article  >  Web Front-end  >  Four common garbled HTML web page problems and their solutions

Four common garbled HTML web page problems and their solutions

PHP中文网
PHP中文网Original
2017-06-06 11:47:312057browse

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"/>

in the 93f0f5c25f18dab9d176bd4f6de5d30e of the web page.

2. PHP character encoding problem

This is similar to the above.

Add:

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

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;

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

.

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

character_set_client 
character_set_connection
character_set_results

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.

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