Home > Backend Development > PHP Tutorial > PHP outputs Chinese JSON string_PHP tutorial

PHP outputs Chinese JSON string_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 14:58:08
Original
807 people have browsed it

PHP and JavaScript are actually very convenient, and PHP also provides native support for JSON format. It mainly includes two functions: JSON encoding and decoding:

json_endoce: http://cn.php.net/json_encode
json_dedoce: http://cn.php.net/json_decodejson_encode — JSON for variables Encode and return the JSON form of value, for example:

$arr = array ('a'=>1,'b'=>2,'c'= >3,'d'=>4,'e'=>5);
echo json_encode($arr);
?>

After the above code is executed, the output is:

{"a":1,"b":2,"c":3,"d":4,"e":5}

If the data source to be encoded (usually an array) contains Chinese in the value, the output after json_encode processing is unicode encoding.

$arr = array ('a'=>'Mango Station');
echo json_encode($arr);
?>

After the above code is executed, the output is:

{"a":"u8292u679Cu5C0Fu7AD9"}

The bottom layer of PHP has already done unicode processing. If you find it not intuitive enough, you can use the urlencode and urldecode methods to bypass the process of transcoding to unicode:

$arr = array ('a'=> urlencode('Mango Station'));
echo urldecode(json_encode($arr)); After the above code is executed, the output is:

{"a":"Mango Station"}

Source: mangguo.org

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/363891.htmlTechArticlePHP and JavaScript are actually very convenient, and PHP natively provides support for JSON format. It mainly includes two functions: JSON encoding and decoding: json_endoce: http://cn.php.net/json_encode js...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template