我有一个php脚本,将返回一个谷歌搜索,但它给了我HTTP错误。
if (strstr(file_get_contents("http://www.google.com/search?q=site:http://". $url ."&gws_rd=ssl"), 'did not match any documents.'))
{
return "No";
}
else {
return "Yes";
}
A PHP Error was encountered
严重性:警告
消息:file_get_contents(http://www.google.com/search?q=site:http://google.com&gws_rd=ssl): failed to open stream: HTTP请求失败!HTTP/1.0 503服务不可用
文件名:库/google_index.php
行号:8
错误:HTTP请求失败!HTTP/1.0 503服务不可用。我怎样才能强制它获取内容呢
如果您将URL作为另一个URL的GET参数,则必须将其urlencode()
。否则,像?
或&
这样的字符将被认为是主URL的一部分。
尝试对整个URL进行编码,如:
$string = "google.com/search?q=site:". urlencode($url ."&gws_rd=ssl")