Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
已脱机的网站上的PHP文件_get_contents()-返回什么?_Php_Web_File Get Contents_Offline - Fatal编程技术网

已脱机的网站上的PHP文件_get_contents()-返回什么?

已脱机的网站上的PHP文件_get_contents()-返回什么?,php,web,file-get-contents,offline,Php,Web,File Get Contents,Offline,这不在php.net上的php文档中,所以我在这里问 如果我(例如)使用$contents=file\u get\u contents(“www.bbc.co.uk/news”)而www.bbc.co.uk/news是离线的,那么file\u get\u contents()会在变量$contents中返回到我的php脚本吗 $contents是否为空?或者,$contents是某种形式的错误吗?(例如)例如 在chrome中查看时?(假设)它应该返回FALSE 请看这里: '失败时,file

这不在php.net上的php文档中,所以我在这里问

如果我(例如)使用
$contents=file\u get\u contents(“www.bbc.co.uk/news”)
www.bbc.co.uk/news
离线的,那么
file\u get\u contents()
会在变量
$contents
中返回到我的php脚本吗

$contents
是否为空?或者,
$contents
是某种形式的错误吗?(例如)例如


在chrome中查看时?(假设)

它应该返回FALSE

请看这里:

'失败时,file_get_contents()将返回FALSE。'

您可以通过输入一个虚假的URL来测试它,即无法访问的URL

您可以使用以下方法检查响应代码(查看是否为404):

file_get_contents("http://example.com");
var_dump($http_response_header);
这摘自对该问题的回答:


但是请注意,在有效的服务器地址上调用无效的url很可能会将您重定向到servers 404页面,该页面将作为字符串下载。是否有方法检测服务器的404页面是否下载了内容@Dognose最好的方法是检查响应代码,请参阅更新的答案。