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

How to convert php unicode encoding to Chinese characters

藏色散人
藏色散人Original
2021-03-10 09:59:123942browse

php Method to convert unicode encoding to Chinese characters: First create a PHP sample file; then use the "function unicodeDecode($unicode_str){...}" method to convert unicode characters into Chinese.

How to convert php unicode encoding to Chinese characters

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

unicode decoding method, convert unicode characters into Chinese, the code is as follows:

function unicodeDecode($unicode_str){
    $json = '{"str":"'.$unicode_str.'"}';
    $arr = json_decode($json,true);
    if(empty($arr)) return '';
    return $arr['str'];
}
 
$unicode_str = "\u65b0\u6d6a\u5fae\u535a";
echo unicodeDecode($unicode_str);

Unicode decoding result: "Sina Weibo"

[Recommended study: " PHP video tutorial》】

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