Home  >  Article  >  Backend Development  >  What should I do if the Chinese output of php array is garbled?

What should I do if the Chinese output of php array is garbled?

青灯夜游
青灯夜游Original
2021-03-23 18:27:342016browse

Solution to garbled Chinese output of php array: First add the "header("Content-type:text/html;charset=utf-8");" code at the beginning of the php document; then save the php document It can be in "UTF-8" format.

What should I do if the Chinese output of php array is garbled?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php array Chinese output garbled code

<?php
$arr1 =array("a"=>"猫","b"=>"狗","c"=>"兔子");
var_dump($arr1);
?>

Output:

array (size=3)
  &#39;a&#39; => string &#39;鐚�&#39; (length=3)
  &#39;b&#39; => string &#39;鐙�&#39; (length=3)
  &#39;c&#39; => string &#39;鍏斿瓙&#39; (length=6)

Solution:

Add the following code at the beginning of the php page, and then save the UTF -8 encoded files are sufficient.

header("Content-type:text/html;charset=utf-8");

Output at this time:

array (size=3)
  &#39;a&#39; => string &#39;猫&#39; (length=3)
  &#39;b&#39; => string &#39;狗&#39; (length=3)
  &#39;c&#39; => string &#39;兔子&#39; (length=6)

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if the Chinese output of php array is garbled?. 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