我从Instagram提取JSON:
$instagrams = json_decode($response)->data;
然后将变量解析为PHP数组以重组数据,然后重新编码和缓存文件:
file_put_contents($cache,json_encode($results));
当我打开缓存文件时,我所有的正斜杠“ /”都被转义了:
http:\/\/distilleryimage4.instagram.com\/410e7...
我从搜索中收集到json_encode()自动执行此操作…是否可以禁用它?
json_encode()
有没有办法禁用它?
是的,您只需要使用该JSON_UNESCAPED_SLASHES标志。
JSON_UNESCAPED_SLASHES
重要的 阅读之前:https : //stackoverflow.com/a/10210367/367456(知道你在做什么- 知道你的敌人)
json_encode($str, JSON_UNESCAPED_SLASHES); <?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/"