使用json_encode和json_decode函数
1、使用json_decode()函数将unicode编码转换为中文汉字:
php
<?php
$str = "\u597d\u597d\u5b66\u4e60\u5929\u5929\u5411\u4e0a";
# echo json_decode($str); # 错误
echo json_decode(sprintf('"%s"', $str)); #正确
注意:需要在要转换成中文的unicode字符串两边添加双引号后,才能使用json_decode()正确的转换成中文。
2、使用json_encode()函数将中文转换为unicode编码:
php
<?php
$str = "爱E族:aiezu.com";
echo json_encode($str);
注意:使用json_encode()函数将中文转换成unicode编码后,首尾会多出两个双引号,需要自行去掉。