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

青灯夜游
Release: 2023-03-08 22:16:02
Original
2017 people have browsed it

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);
?>
Copy after login

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)
Copy after login

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");
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template