PHP URL判断

判断URL是否可用:
function url_exists($url)
{  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$url);//set an url
  curl_setopt($ch, CURLOPT_NOBODY, 1); // and *only* get the header
  curl_setopt($ch, CURLOPT_FAILONERROR, 1);//stop if an error occurred
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            //do not output directly, use variable or get the response as a string from curl_exec(), rather than echoing it

return (curl_exec($ch)!==false) ? true : false;
}
$url = 'http://www.google.com';
$re = url_exists($url);
var_dump($re);

你可能感兴趣的:(PHP,url)