How to check URL is valid or not in PHP

I am explaining you, How to check URL is valid or not in PHP.
I am going to explaining, how to check if a URL is valid in PHP using filter_var() function with FILTER_VALIDATE_URL filter. Use the following code to check if the URL is valid or not.

Example :

<?php

  $urlcheck = "https://webdeveloperindia.in";
  if (!filter_var($urlcheck, FILTER_VALIDATE_URL) === false) {
    echo("this Url is valid");
  } else {
    echo("this Url is not valid");
  }

?>

Result:

this Url is valid

Leave a Reply

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

− 1 = 1