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.
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.
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
##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.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!