如下代码:

<?php

echo json_encode("http://www.google.com/"), "\n";

<?>

会输出:

"http:\/\/www.google.com\/"

在PHP 5.4以后,json_encode()增加了几个参数,其中JSON_UNESCAPED_SLASHES就是用来解决这个问题的:

<?php

echo json_encode("http://www.google.com/", JSON_UNESCAPED_SLASHES), "\n";

<?>

输出:

http://www.google.com/