Here is the best example to check URL is valid or not, We will use filter_var PHP function and FILTER_VALIDATE_URL Flags

#example_one.php

<?php

$url = "https://www.rathorji.in";

if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
    die('Not a valid URL');
} else {
    echo "Valid URL";
}
?>

Here is the another code example for validating URL 

<?php

$url = "https://www.rathorji.in";

if (preg_match('/^(http|https):\\/\\/[a-z0-9_]+([\\-\\.]{1}[a-z_0-9]+)*\\.[_a-z]{2,5}' . '((:[0-9]{1,5})?\\/.*)?$/i', $url)) {
   echo "URL is Valid";
} else {
     echo "Give URL is not Valid";
}
?>

output:

URL is Valid