大马资讯论坛 - 马来西亚中文资讯平台

 找回密码
 注册
搜索

[教学] php 如何把json输出的中文unicode转为字体?

[复制链接]
发表于 2013-7-28 18:24:59 | 显示全部楼层 |阅读模式
只要弄Regex的方法就搞定,把json输出的中文unicode转为字体。
  1. $unicodeChar = "\u56de\u590d\uff1a";
  2. function unicodeString($str, $encoding=null) {
  3.         return preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/u', create_function('$match', 'return mb_convert_encoding(pack("H*", $match[1]), "utf-8", "UTF-16BE");'), $str);
  4. }
  5. echo  unicodeString($unicodeChar);
复制代码

手机版|大马资讯论坛  

GMT+8, 2024-3-28 22:21 , Processed in 0.134457 second(s), 15 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表