有没有办法禁用它?
是的,您只需要使用JSON_UNESCAPED_SLASHES
的旗子就可以了.
!important以前读过:https://stackoverflow.com/a/10210367/367456(知道你在和什么打交道--知道你的敌人)
json_encode($str, JSON_UNESCAPED_SLASHES);
如果你手头没有PHP5.4,从现有的许多函数中 Select 一个,并根据需要修改它们,例如http://snippets.dzone.com/posts/show/7487 (archived copy).
Example Demo个
<?php
/*
* Escaping the reverse-solidus character ("/", slash) is optional in JSON.
*
* This can be controlled with the JSON_UNESCAPED_SLASHES flag constant in PHP.
*
* @link http://stackoverflow.com/a/10210433/367456
*/
$url = 'http://www.example.com/';
echo json_encode($url), "\n";
echo json_encode($url, JSON_UNESCAPED_SLASHES), "\n";
输出示例:
"http:\/\/www.example.com\/"
"http://www.example.com/"