The code below will let you to check a valid URL in PHP. When we need to validate an input field that only accepts URL, you can use the following code:

<?php
if (!preg_match("~^(?:f|ht)tps?://~i", $uri)) {
    $uri = "http://" . $uri;
}
if(preg_match( '/^(http|https):\\/\\/[a-z0-9_]+([\\-\\.]{1}[a-z_0-9]+)*\\.[_a-z]{2,5}'.'((:[0-9]{1,5})?\\/.*)?$/i' ,$uri)){
  echo $uri;
}
else{
    echo 'false';
} ?>