Solution to the garbled code returned by php in Chinese: 1. Add the code "charset=UTF-8" in the head tag; 2. Set the encoding to "UTF-8" when saving the file; 3. Set the PHP encoding to "charset=utf-8"; 4. Mysql encoding is set to "NAMES UTF8".
Recommended: "PHP Video Tutorial"
php output Chinese garbled code problem
Many beginners may encounter the problem of outputting garbled Chinese characters when they first start learning PHP;
The methods to solve this problem are nothing more than the following:
1 , HTML page encoding settings
1. Add this sentence
<head> <metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/> </head>
in the head tag 2. Set the encoding to UTF-8 when saving the file.
2. PHP encoding settings
Based on method one, write
<?php header("Content-type:text/html;charset=utf-8"); ?>
at the very beginning of the PHP code, i.e. the first sentence. 3. Mysql encoding settings
Based on the previous ones, you also need to add database coding before querying/modifying/adding your data.
<?php mysql_query('SET NAMES UTF8'); ?>
Note that UTF8 is written here instead of UTF-8! ! !
Following the above method settings should be able to solve the problem of outputting Chinese garbled characters.
The above is the detailed content of What should I do if php Chinese returns garbled characters?. For more information, please follow other related articles on the PHP Chinese website!