Home > Article > Backend Development > What to do if php outputs array key names with garbled characters
Solution to the garbled array key name output by php: 1. Add "header("Content-type:text/html;charset=utf-8");" at the beginning of the page; 2. Execute " mysql_query('SET NAMES UTF8');".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What should I do if php outputs garbled array key names? ?
1. The Chinese garbled problem of pure PHP pages (data is static)
You only need to add the following code at the beginning of the page, and then save the UTF-8 encoded file That’s it.
<?php header("Content-type:text/html;charset=utf-8"); ?>
2. PHP Mysql Chinese garbled problem
In addition to following the operations mentioned in the first point, you must also add database encoding before querying/modifying/adding your data. Moreover, it is worth noting that the UTF8 here is different from the previous one, there is no horizontal line in the middle.
<?php mysql_query('SET NAMES UTF8'); //接下来的就是查出数据或者修改,增加 ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if php outputs array key names with garbled characters. For more information, please follow other related articles on the PHP Chinese website!