PHP url validation using filter_var() function

You can validate url using php filter_var() function using following code.

$url = 'http://mywebsite.com';
$result = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED);
if ( $result )
{
echo 'Valid URL';
}
else 
{
$output = 'Not A Valid URL';
}

Leave a Reply

Your email address will not be published. Required fields are marked *