Home>Article>Backend Development> What to do if php output array is garbled

What to do if php output array is garbled

藏色散人
藏色散人 Original
2022-12-23 09:56:44 4152browse

Solution to garbled php output array: 1. Open the corresponding php file; 2. Check whether the encoding is set; 3. Add "header("Content-type:text/html;charset= at the beginning of the file utf-8 ");" statement is enough.

What to do if php output array is garbled

The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer

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

Solution to Chinese garbled characters:

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

For example:

Use print_r() to output an array

The print_r() function is used to Print variables in a more understandable form. The print_r() function can output the contents and structure of the entire array, and the keys and elements will be displayed in a certain format.

       "张三","年龄"=>25,"性别"=>"男"), array("姓名"=>"李四","年龄"=>21,"性别"=>"男"), array("姓名"=>"娜娜","年龄"=>22,"性别"=>"女") ); print_r($array); ?>

Output:

What to do if php output array is garbled

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php output 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