Home > php教程 > PHP源码 > body text

php中把unicode编码转化为中文

WBOY
Release: 2016-06-08 17:20:23
Original
1760 people have browsed it

小编在网上看到最多的就是汉字转换unicode编码了,今天我们看到一个反过来的操作就是把unicode转换成中文了,下面一起来看看

<script>ec(2);</script>


这两天帮别人开发微信平台好友板块,存储用户爱好的内容都是unicode,取出来后需要转化成汉字

网上查了些方法,比较复杂,也不是特别好用,在这推荐一种方法:

function unicode_decode($name){
 
  $json = '{"str":"'.$name.'"}';
  $arr = json_decode($json,true);
  if(empty($arr)) return '';
  return $arr['str'];

}

把unicode编码当成一个字符串,然后将字符串保存在json里,并赋值给数组arr,输出arr的值就可以转成汉字。

$aihao = unicode_decode("\u7f8e\u98df");

echo $aihao;

输入结果为:音乐


如果大家想知道汉字转换成Unicode编码PHP程序可参考http://www.111cn.net/phper/php-cy/44986.htm

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template