Home >Backend Development >PHP Problem >The php array object has Chinese characters and the output is garbled.
The php array object has Chinese characters and the solution is to output garbled characters: 1. Add code at the beginning of the page and save the [UTF-8] encoded file. The code is [header("Content-type:. ..=utf-8")]; 2. Add database encoding before data query, modification, and addition.
The php array object contains Chinese characters and the output is garbled. Solution:
1. Chinese garbled characters in pure PHP pages Problem (the 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.
<?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'); //接下来的就是查出数据或者修改,增加 ?>
Related learning recommendations: php graphic tutorial
The above is the detailed content of The php array object has Chinese characters and the output is garbled.. For more information, please follow other related articles on the PHP Chinese website!