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