Php checks whether the URL is valid. 1 .? URL format :? FunctioncheckUrl ($ weburl) {return! Ereg (^ http (s) *: [_ a-zA-Z0-9-] + (. [_ a-zA-Z0-9-] +) * $, $ weburl );}? 2 .? Determine whether the http address is valid? Functionurl_exists php checks whether the URL is valid
1 .? URL format:
?
function checkUrl($weburl) { return !ereg("^http(s)*://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", $weburl); }
?
2 .? Determine whether the http address is valid
?
Function url_exists ($ url) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_NOBODY, 1 ); // do not download curl_setopt ($ ch, CURLOPT_FAILONERROR, 1); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); return (curl_exec ($ ch )! = False )? True: false ;}
?
Or
?
function img_exists($url) {return file_get_contents($url,0,null,0,1) ? true : false;}
?
Or
?
function url_exists($url) {$head = @get_headers($url); return is_array($head) ? true : false;}
?
Instance:
?
$url='http://www.qq.com';echo url_exists($url);
?
?
?
?