PHP file_get_contents返回false [英] PHP file_get_contents returning false
本文介绍了PHP file_get_contents返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
也许我在这里呆了太久,但是为什么file_get_contents在这里返回false,我剪切并粘贴了URL并可以正常工作?
Maybe i've been sat here too long staring at this but WHY would file_get_contents return false here, i've cut and paste the URL and it works fine?
$url = "http://jobs.github.com/positions.json?search=" . $as_any . "&location=" . $location;
// URL contains http://jobs.github.com/positions.json?search=Project Manager&location=London
var_dump($url);
$json = file_get_contents($url);
var_dump($json);
$results = json_decode($json, TRUE);
var_dump($results);
exit;
谢谢
马克
我已经检查了allow_url_fopen及其确定的地址.
I Have checked for allow_url_fopen and its definately on.
推荐答案
尝试一下:
$query = http_build_query(array('search'=>$as_any, 'location'=>$location));
$url = "http://jobs.github.com/positions.json?" . $query;
问题是您没有对包含空格的搜索词进行URL编码.该请求正在从服务器返回400错误,如果您启用了错误报告,则会注意到该错误.
The problem is that you weren't URL-encoding the search term, which contains a space. The request was returning a 400 error from the server, which you'd have noticed if you had error reporting enabled.
这篇关于PHP file_get_contents返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文