PHP HTML Chinese garbled code problem
1. First, let’s talk about the solution to the HTML Chinese garbled code problem.
Add this sentence in the head tag
<head> <meta charset="UTF-8"> </head>
2. HTML and PHP mixed page solution.
<?php header("Content-type:text/html;charset=utf-8"); ?>
3. PHP Mysql Chinese garbled problem
<?php mysql_query('SET NAMES UTF8'); ?>
UTF-8 encoding is just an encoding. If you don’t want to use utf-8 encoding, you can also use it. For other encodings, just replace UTF-8 with the encoding you want to use. Currently, GB2312 and UTF-8 are mainly used in Chinese website development.
Note: The mysql_query("set names 'encoding'"); encoding is added before the PHP program that needs to perform database operations. The encoding 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 UTF-8, so that there will be no garbled characters when inserting or retrieving data.
Related tutorial recommendations: "PHP Tutorial"
The above is the detailed content of How to solve the Chinese garbled characters in php html?. For more information, please follow other related articles on the PHP Chinese website!