分享一段处理多维数组,unidecode的中文的字符的代码

Example:

<?php
$params = '{

    "country":"\\u4e2d\\u56fd",

    "items0":{

        "message":"\\u6211\\u4f1f\\u5927\\u7684\\u7956\\u56fd",

        "remark":["\\u6211\\u7231\\u6211\\u7684\u7956\\u56fd"]

    },

    "items1":{

        "message":"\\u6211\\u4f1f\\u5927\\u7684\\u7956\\u56fd",

        "remark":["\\u6211\\u7231\\u6211\\u7684\u7956\\u56fd"]

    }

}';
function unicodeDecode(&$params){

  if(is_array($params)){

  foreach ($params as $key => &$value){

  $params[$key] = $this->unicodeDecode($value);

  }

  return $params;

  }else{

  return preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/i', function($match){

  return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');

  }, $params);

  }

}

$this->unicodeDecode($params);
print_r($params);
php
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 1

你用jsondecode指定无符号编码就是中文了

2年前 评论
zhangwuphp (楼主) 2年前
raybon (作者) 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!