Home  >  Article  >  Backend Development  >  How to convert unicode to Chinese in php

How to convert unicode to Chinese in php

藏色散人
藏色散人Original
2020-07-14 09:03:529119browse

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);
}

实测好用。

更多相关知识,请访问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!

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