1 function replace_unicode_escape_sequence($match) { 2 return mb_convert_encoding(pack(‘H*‘, $match[1]), ‘UTF-8‘, ‘UCS-2BE‘); 3 } 4 $name = ‘\u65b0\u6d6a\u5fae\u535a‘; 5 $str = preg_replace_callback(‘/\\\\u([0-9a-f]{4})/i‘, ‘replace_unicode_escape_sequence‘, $name); 6 echo $str; //输出: 新浪微博 7 // www.jbxue.com 脚本学堂 8 //咱将上述方案A给封装起来~~~(方案A稳定版+升级+推荐) 9 class Helper_Tool 10 { 11 static function unicodeDecode($data) 12 { 13 function replace_unicode_escape_sequence($match) { 14 return mb_convert_encoding(pack(‘H*‘, $match[1]), ‘UTF-8‘, ‘UCS-2BE‘); 15 } 16 17 $rs = preg_replace_callback(‘/\\\\u([0-9a-f]{4})/i‘, ‘replace_unicode_escape_sequence‘, $data); 18 19 return $rs; 20 } 21 } 22 //调用 23 $name = ‘\u65b0\u6d6a\u5fae\u535a‘; 24 $data = Helper_Tool::unicodeDecode($name); //输出新浪微博
时间: 2024-10-06 23:43:18