php 检测网址是否有效
1. ?网址的格式:
?
function checkUrl($weburl)
{
return !ereg("^http(s)*://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", $weburl);
}
?
2 .?判断http 地址是否有效
?
function url_exists($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_NOBODY, 1); // 不下载
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return (curl_exec($ch)!==false) ? true : false;
}
?
或者
?
function img_exists($url)
{
return file_get_contents($url,0,null,0,1) ? true : false;
}
?
或者
?
function url_exists($url)
{
$head = @get_headers($url);
return is_array($head) ? true : false;
}
?
实例:
?
$url='http://www.qq.com';
echo url_exists($url);
?
?
?
?
本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉
本文系统来源:php中文网