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

不言
Release: 2023-04-03 16:50:02
Original
8963 people have browsed it

这篇文章给大家介绍的内容是关于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);
}
Copy after login

JS的方式为:

<script type=text/javascript>

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

</script>
Copy after login

小小记录下。。。

相关文章推荐:

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!