Common problems and solutions to garbled web pages

*文
Release: 2023-03-18 18:14:01
Original
9757 people have browsed it

When we make web pages, we often encounter Chinese garbled web pages. So how to solve this problem? Below, the editor of Script House will share with you four common html web page garbled problems and solutions. Friends in need can refer to Down. I hope to be helpful.

When my colleagues were working on a web page last week, they encountered garbled characters after opening the web page. The colleague was very confused and didn’t know how to solve it. The following is the editor’s time to find out the common garbled HTML web page problems and their solutions. The methods are compiled and shared with everyone.

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 of the web page:


##

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



is enough.


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 problem 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 problem

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


Use root to enter the database,


Enter show variables like 'character%'


You can see


character_set_client

character_set_connection
character_set_database
character_set_filesystem
character_set_results
character_set_server
character_set_system

These 7 values.


The set names ut8 command can set these three


character_set_client

character_set_connection
character_set_results

to utf8 .


So when creating a MySQL database, pay attention to setting 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.


Related recommendations:

php garbled code problem [solution]_PHP tutorial

How to solve garbled characters in ThinkPHP?

utf-8-PHP The persistent problem of garbled codes--partially garbled codes

The above is the detailed content of Common problems and solutions to garbled 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
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!