pTutorial

New way to learn Programming

How To Validate A URL In PHP

How to validate a URL in PHP

PHP validate URl: Here we’ll provide the PHP code to validate a URL with the help of filter_var() function and FILTER_VALIDATE_URL constant filter.

PHP validate URL

<?php
$tempurl = "http://www.google.com";

if (!filter_var($tempurl, FILTER_VALIDATE_URL) === false) {
    echo("Given URL is valid");
} else {
    echo("Given URL is not valid");
}
?>

Output

Given URL is valid

See Also


QUOTES OF THE DAY

Well-begun is half done.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER