-
- /**
- desc: Check whether the network address format is valid
- link: bbs.it-home.org
- date: 2013/2/24
- */
- function checkUrl($weburl)
- {
- return !ereg("^http(s)*://[_a-zA-Z0-9 -]+(.[_a-zA-Z0-9-]+)*$", $weburl);
- } ?>
-
Copy code
2. Determine whether the http address is valid
-
-
/** - desc: Check whether the http address is valid
- link: bbs.it-home.org
- date: 2013/2/24
- */
- 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;
- }
//Method 2
- function img_exists($url)
- {
- return file_get_contents($url,0,null,0,1) ? true : false;
- }
//Method 3:
- function url_exists($url)
- {
- $head = @get_headers($url);
- return is_array($head) ? true : false;
- } ?>
-
Copy code
Call example:
-
- $url='http://bbs.it-home.org';
- echo url_exists($url);
- ?>
Copy code
|