How to restore the json data used by js using php. $ Str = file_get_contents ("http://news.soso.com/frontpage.q? Ty = 1 & amp; city = % E6 % B2 % B3 % E6 % BA % 90 "); $ str = stripslashes ($ str ); echo uses php to restore the json data used by js.
$ Str = file_get_contents ("http://news.soso.com/frontpage.q? Ty = 1 & city = % E6 % B2 % B3 % E6 % BA % 90 ");
$ Str = stripslashes ($ str );
Echo json_decode ($ str); // data cannot be output here.
Share:
------ Solution --------------------
$str = file_get_contents("http://news.soso.com/frontpage.q?ty=1&city=%E6%B2%B3%E6%BA%90");
$str = stripslashes(substr($str, 12, -1));
print_r(json_decode($str));
Http://news.soso.com/fro... returns js code, not json
------ Solution --------------------
$str = file_get_contents("http://news.soso.com/frontpage.q?ty=1&city=%E6%B2%B3%E6%BA%90");
$str = stripslashes(substr($str, strpos($str, "'")+1, -1));
json_decode($str, true)
------ Solution --------------------
Because the returned result contains var result =, PHP must replace var result = with regular expressions before using the josn format.
Use regular/var \ s + result \ = \ '([^'] + ?) \ '/, And then use json_decode.