Home  >  Article  >  Backend Development  >  What to do if php outputs array key names with garbled characters

What to do if php outputs array key names with garbled characters

藏色散人
藏色散人Original
2022-01-17 09:35:261339browse

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');".

What to do if php outputs array key names with garbled characters

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(&#39;SET NAMES UTF8&#39;);
//接下来的就是查出数据或者修改,增加
?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn