1. 网址的格式:
Java代码
function checkUrl($weburl)
{
return !ereg("^http(s)*://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", $weburl);
}
2 . 判断http 地址是否有效
Php代码
function url_exists($url)
{
$ch = curl_init(); //此处需要要在php.ini里打开extension=php_curl.dll项,即去掉前面分号
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;
}
或者
Php代码
function img_exists($url)
{
return file_get_contents($url,0,null,0,1) ? true : false;
}
或者
Php代码
function url_exists($url)
{
$head = @get_headers($url);
return is_array($head) ? true : false;
}
实例:
Php代码
$url='http://www.hilo8.com';
echo url_exists($url);
上一篇:PHP函数string mb_detect_encoding判断字符/页面的编码格式
下一篇:PHP必备的函数集
讨论数量:0