Home >Backend Development >PHP Problem >How to solve garbled characters in php?

How to solve garbled characters in php?

青灯夜游
青灯夜游Original
2019-10-11 15:59:002550browse

I just learned PHP, and garbled characters often appear when writing projects. So how to solve the garbled code in php? The following article will introduce to you the solution to garbled characters in PHP. I hope it will be helpful to you.

How to solve garbled characters in php?

The PHP file output is garbled

Whether it is a garbled page mixed with HTML and PHP, or a garbled problem with a pure PHP page ( The data is static), and the encoding of PHP itself needs to match the encoding of the HTML web page.

Use the header() statement to keep the PHP encoding consistent with the encoding of the web page.

How to solve garbled characters in php?

The data interaction between PHP and MySQL appears garbled

At this time, the encoding of PHP and the database must be consistent.

If you are using MySQL version 4.1 or higher, you can set a character encoding after the link database operation, like the following

How to solve garbled characters in php?

##UTF -8 encoding is just one of the encodings. If you don’t want to use utf-8 encoding, you can also use other encodings. Just replace UTF-8 with the encoding you want to use. Currently, GB2312 and UTF are mainly used in website development. -8 Two encodings.


One thing to note is that the mysql_query("set names 'coding'"); encoding added before the PHP program that needs to perform database operations must be consistent with the PHP encoding. If the PHP encoding is gb2312, then the mysql encoding is gb2312. If it is utf-8, then the mysql encoding is utf8, so that there will be no garbled characters when inserting or retrieving data

How to solve garbled characters in php?

The above is the detailed content of How to solve garbled characters in php?. For more information, please follow other related articles on the PHP Chinese website!

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