php json 中文转化

public static function decodeUnicode($str)
{
return preg_replace_callback(
'/\\\\u([0-9a-f]{4})/i',
function($matches){
return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");
},
$str);
}


  1. <?php
  2. echo json_encode("中文", JSON_UNESCAPED_UNICODE);

 

preg_replace_callback 函数执行一个正则表达式搜索并且使用一个回调进行替换。

posted @ 2020-03-31 11:12  agang_19  阅读(388)  评论(0编辑  收藏  举报