Home > Backend Development > PHP Problem > How to convert unicode to Chinese in php

How to convert unicode to Chinese in php

藏色散人
Release: 2023-03-02 14:16:01
Original
9171 people have browsed it

php将unicode转换中文的方法:首先创建一个PHP示例文件;然后定义一个decodeUnicode方法;接着在方法体内通过“preg_replace_callback”等函数方法实现unicode转换中文的效果;最后执行相关文件即可。

How to convert unicode to Chinese in php

php把unicode转化成中文实用方法

//把unicode转化成中文
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

实测好用。

更多相关知识,请访问PHP中文网

The above is the detailed content of How to convert unicode to Chinese in php. 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