note 118938 added to function.parse-url
| From: | ivijan dot stefan at gmail dot com | Date: | Wed, 02 Mar 2016 13:23:27 +0000 |
| Subject: | note 118938 added to function.parse-url | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205085@lists.php.net to get a copy of this message | ||
If you need check if URL exists or not, here is one my good function for that.
<?php
// Return false or URL
function url_exists($url='')
{
if(empty($url)) return false;
$curl = curl_init($url);
//don't fetch the actual page, you only want to check the connection is ok
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT ,5);
curl_setopt($curl, CURLOPT_TIMEOUT , 2);
//do request
$result = curl_exec($curl);
//if request did not fail
if ($result !== false) {
//if request was ok, check response code
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ((int)$statusCode === 200) return $url;
return false;
}
curl_close($curl);
return false;
}
if(url_exists("http://www.google.com")!==false)
{
// URL Exists
}
?>
This can help if you decide to do some dynamic URL parser or something where need validations.
----
Server IP: 72.52.91.14
Probable Submitter: 78.30.128.161
----
Manual Page -- http://php.net/manual/en/function.parse-url.php
Edit -- https://master.php.net/note/edit/118938
Del: integrated -- https://master.php.net/note/delete/118938/integrated
Del: useless -- https://master.php.net/note/delete/118938/useless
Del: bad code -- https://master.php.net/note/delete/118938/bad+code
Del: spam -- https://master.php.net/note/delete/118938/spam
Del: non-english -- https://master.php.net/note/delete/118938/non-english
Del: in docs -- https://master.php.net/note/delete/118938/in+docs
Del: other reasons-- https://master.php.net/note/delete/118938
Reject -- https://master.php.net/note/reject/118938
Search -- https://master.php.net/manage/user-notes.php