preg_match function and regular expression to check url is valid or not if it is valid it will show message url is valid other message will be url is invalid


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

Run the following code and see the result

Output: is valid URL