json_endoce: http://cn.php.net/json_encode json_dedoce: http://cn.php.net/json_decode
json_encode — JSON encodes the variable and returns the JSON form of the value, for example:
<?php $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); echo json_encode($arr); ?>
The output after the above code is executed:
{"a":1,"b":2,"c":3,"d":4,"e":5}
If the data source to be encoded (generally is an array), the value contains Chinese, and the output after json_encode processing is unicode encoding.
<?php $arr = array ('a'=>'脚本之家'); echo json_encode($arr); ?>
The output after the above code is executed:
{"a":"\u811a\u672c\u4e4b\u5bb6"}
The bottom layer of PHP has been processed by unicode. If you think it is not intuitive enough, you can use the urlencode and urldecode methods to bypass the process of transcoding to unicode:
$arr = array ('a'=>urlencode('PHP中文网')); echo urldecode(json_encode($arr));
After the above code is executed, the output is:
{"a":"PHP中文网"}
For more related articles that teach you how to use PHP to output Chinese JSON strings, please pay attention to the PHP Chinese website!