如何在 PHP 中检查 URL 是否存在(不是 404)?
最佳答案
这里:
$file = 'http://www.example.com/somefile.jpg';
$file_headers = @get_headers($file);
if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
$exists = false;
}
else {
$exists = true;
}
来自 here和 right below上面的帖子,有一个curl解决方案:
function url_exists($url) {
return curl_init($url) !== false;
}
关于php - 如何通过 PHP 检查 URL 是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2280394/