In this tutorial, we will learn How to validate whether a URL is valid or not using PHP.
To validate a URL, we will use filter_var() function with FILTER_VALIDATE_URL filter.
<?php
$url = “https://phpgurukul.com”;
if (!filter_var($url, FILTER_VALIDATE_URL) === false) {
echo(“Url is valid”);
} else {
echo(“Url is not valid”);
}
?>
Output will be: Url is valid
The post How to check if a URL is valid or not in PHP appeared first on PHPGurukul.