如何通过PHP检查URL是否存在? [英] How can I check if a URL exists via PHP?

查看:107
本文介绍了如何通过PHP检查URL是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查PHP中是否存在URL(不存在404)?

How do I check if a URL exists (not 404) in PHP?

推荐答案

此处:

$file = 'http://www.domain.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;
}

此处

From here and right below the above post, there's a curl solution:

function url_exists($url) {
    if (!$fp = curl_init($url)) return false;
    return true;
}

这篇关于如何通过PHP检查URL是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆