How to solve php html garbled code

藏色散人
Release: 2023-03-07 22:16:01
Original
3250 people have browsed it

php html garbled solution: 1. Add "charset=utf8" to the web page; 2. Modify the encoding of the file itself to utf8; 3. Set the character set and sorting rules when creating the database in MySQL It can be utf8.

How to solve php html garbled code

Recommended: "PHP Video Tutorial"

The operating environment of this tutorial: Windows 7 system, PHP version 7.1, Dell G3 computer, this method is suitable for all brands of computers.

Solution to php html garbled code

When making a web page by yourself, you often encounter the problem of garbled web pages.

In fact, there are several main reasons that lead to 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 in the page:

is enough.

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 problem of the file itself

Not only our content is 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 problem

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,

Enter show variables like 'character%'

You can see the 7 values ​​

character_set_client 

character_set_connection
character_set_database
character_set_filesystem
character_set_results
character_set_server

character_set_system
Copy after login

.

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 database in MySQL, pay attention to setting the character set and collation rule 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 is the detailed content of How to solve php html garbled code. 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
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!