Home  >  Article  >  Backend Development  >  Two implementation methods for converting UNICODE encoding into Chinese characters (php and js)

Two implementation methods for converting UNICODE encoding into Chinese characters (php and js)

不言
不言Original
2018-08-06 15:50:359139browse

这篇文章给大家介绍的内容是关于UNICODE编码转换为中文汉字的两种实现方式(php和js),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

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>

小小记录下。。。

相关文章推荐:

PHP中常用的一些功能总结(归纳)

Nginx中的Rewrite伪静态法则的讲解(详细)

The above is the detailed content of Two implementation methods for converting UNICODE encoding into Chinese characters (php and js). For more information, please follow other related articles on the PHP Chinese website!

Statement:
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