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

How to convert unicode to Chinese characters

藏色散人
Release: 2023-03-02 12:56:02
Original
6716 people have browsed it

unicode转汉字的方法:首先百度搜索“unicode在线工具”;然后输入内容并获得unicode结果;接着创建PHP文件,编辑内容为“function u2c($str){...}”;最后在浏览器中运行该文件即可。

How to convert unicode to Chinese characters

百度搜索“unicode在线工具”,我们以“武汉加油,中国加油”为例,unicode结果如下:

武汉加油,中国加油
Copy after login

How to convert unicode to Chinese characters

新建文件,编辑内容如下:

function u2c($str){   
return preg_replace_callback("#\\\u([0-9a-f]{4})#i",      
function ($r) {
return iconv('UCS-2BE', 'UTF-8', pack('H4', $r[1]));},       
$str);
}
echo u2c('\u53ea\u80fd\u4e2d\u6587\u624d\u61c2\u6211');
Copy after login

How to convert unicode to Chinese characters

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

The above is the detailed content of How to convert unicode to Chinese characters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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