Below code shows validation of URL in php using preg_match function of php

#example.php

<?php

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

if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $website)) {
    echo "Invalid URL";
} else {
    echo "valid URL";
}
?>


Above the syntax will verify whether the given URL is valid or not. It should allow certain keywords like https, ftp, www, a-z, 0-9, .. etc.


output:

valid URL