Home > Backend Development > PHP Tutorial > php 检测因特网址是否有效

php 检测因特网址是否有效

WBOY
Release: 2016-06-13 13:11:24
Original
1327 people have browsed it

php 检测网址是否有效

1. ?网址的格式:

?

function checkUrl($weburl) 
{ 
	return !ereg("^http(s)*://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", $weburl); 
}
Copy after login
?

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;
}
Copy after login

?

或者

?

function img_exists($url) 
{
	return file_get_contents($url,0,null,0,1) ? true : false;
}
Copy after login

?

或者

?

function url_exists($url) 
{
	$head = @get_headers($url);
    return is_array($head) ?  true : false;
}
Copy after login

?

实例:

?

$url='http://www.qq.com';
echo url_exists($url);
Copy after login

?

?

?

?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template