PHP json_encode 如何防止 中文和斜杠 转义
有如下数组, 进行json格式化
$data = array(
   'name' => '中文字符',
   'url' => 'https://www.edoou.com'
);
printf(json_encode($data));输出:
{"name":"\u4e2d\u6587\u5b57\u7b26","url":"https:\/\/www.edoou.com"}可以看到中文和网址中的/都被转义了。防止转义方法如下:
// 防止中文被转义
json_encode($data,JSON_UNESCAPED_UNICODE)
//防止斜杠被转义
json_encode($data,  JSON_UNESCAPED_SLASHES)
//同时防止中文、斜杠被转义
json_encode($data,JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES) 
             
             
             
             
            