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 函数执行一个正则表达式搜索并且使用一个回调进行替换。

原文地址:https://www.cnblogs.com/agang-php/p/12603812.html