PHP小技巧之UNICODE编码转中文汉字

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luyaran/article/details/81449219

PHP的方式为:

function decodeUnicode($str)
{
    return preg_replace_callback('/\\\\u([0-9a-f]{4})/i',
        create_function(
            '$matches',
            'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'
        ),
        $str);
}

JS的方式为:

<script type=text/javascript>

    document.write("UNICODE编码字符串");

</script>

小小记录下。。。

猜你喜欢

转载自blog.csdn.net/luyaran/article/details/81449219