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

相关文章:

  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2021-05-23
  • 2023-03-29
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2021-10-03
相关资源
相似解决方案