PHP头条
热点:

怎么把js用的json数据,用php来还原


如何把js用的json数据,用php来还原。
$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);   //这里老是不能输出数据。









分享到:
------解决方案--------------------
$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..... 返回的是 js 代码,而不是 json

------解决方案--------------------

$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)

------解决方案--------------------
因为那个返回的是带有var result=这个的,那么PHP必须经过正则替换掉var result=等代码以后方可使用josn格式

用正则/var\s+result\=\'([^']+?)\'/来替换掉,然后再用json_decode就OK了

www.phpzy.comtrue/phprm/7185.htmlTechArticle怎么把js用的json数据,用php来还原 如何把js用的json数据,用php来还原。 $str=file_get_contents("http://news.soso.com/frontpage.q?ty=1 $str=stripslashes($str); echojson_decode($str);//这里老是不能输出数据。 分...

相关文章

相关频道:

PHP之友评论

今天推荐