Instead of hacking over the regex (the URLs are very complex), I just use filter_var()and then try ping the URL using cURL :
if (filter_var($url, FILTER_VALIDATE_URL) !== false)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status_code >= 200 && $status_code < 400)
{
echo 'URL is valid!';
}
}
source
share