当前位置:Gxlcms > PHP教程 > php检测因特网址是否有效

php检测因特网址是否有效

时间:2021-07-01 10:21:17 帮助过:22人阅读

php 检测网址是否有效

1. ?网址的格式:

?

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

2 .?判断http 地址是否有效

?

  1. function url_exists($url)
  2. {
  3. $ch = curl_init();
  4. curl_setopt($ch, CURLOPT_URL,$url);
  5. curl_setopt($ch, CURLOPT_NOBODY, 1); // 不下载
  6. curl_setopt($ch, CURLOPT_FAILONERROR, 1);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  8. return (curl_exec($ch)!==false) ? true : false;
  9. }

?

或者

?

  1. function img_exists($url)
  2. {
  3. return file_get_contents($url,0,null,0,1) ? true : false;
  4. }

?

或者

?

  1. function url_exists($url)
  2. {
  3. $head = @get_headers($url);
  4. return is_array($head) ? true : false;
  5. }

?

实例:

?

  1. $url='http://www.qq.com';
  2. echo url_exists($url);

?

?

?

?

人气教程排行