How to check if a URL is valid or not in PHP
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.
1 2 3 4 5 6 7 8 |
<?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