如何关闭或防止 php glob 转义反斜杠?
使用这个 php 代码:
<? header('Content-type: application/json'); ?>
<?
$files = glob("sources/".$_GET['dir'].'/img/*');
echo json_encode($files);
?>
我得到:
["sources\/nine\/img\/0010.jpg","sources\/nine\/img\/0011.jpg"]
但我想要:
["sources/nine/img/0010.jpg","sources/nine/img/0011.jpg"]
with this php code:
<? header('Content-type: application/json'); ?>
<?
$files = glob("sources/".$_GET['dir'].'/img/*');
echo json_encode($files);
?>
I'm getting:
["sources\/nine\/img\/0010.jpg","sources\/nine\/img\/0011.jpg"]
But i want:
["sources/nine/img/0010.jpg","sources/nine/img/0011.jpg"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,这不是
glob()
,这是json_encode()
所做的,而且完全没问题:它按照 JSON 标准的建议转义了斜杠。请参阅此 php.net 错误报告以进行进一步讨论。Actually, this is not
glob()
, this isjson_encode()
's doing and it's perfectly okay: It's escaping slashes as suggested by the JSON standard. See this php.net bug report for further discussion.