PHP-解码unicode编码的中文字符

在Python中使用 "uxxxx".decode("unicode_escape")

1.

class Helper_Tool {
    public static function unicodeDecode($data) {
        function replace_unicode_escape_sequence($match) {
            return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
        }  

        $rs = preg_replace_callback('/\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $data);

        return $rs;
    }
}

$str = '{"name": "u9a8cu8bc1u7801u56feu7247u9ad8u5ea6uff08u5355u4f4duff09"}';
echo Helper_Tool::unicodeDecode($str);

2.此方法字符串中不能有引号

function unicodeDecode($name){
    $json = '{"str":"'.$name.'"}';
    $arr = json_decode($json,, True);
    return empty($arr) ? '' : $arr['str'];
}
原文地址:https://www.cnblogs.com/JohnABC/p/5082847.html