The FILTER_VALIDATE_URL filter validates the value as a URL.
Name: "validate_url"
ID-number: 273
Possible signs:
FILTER_FLAG_SCHEME_REQUIRED - requires the URL to be an RFC compliant URL (such as http://example)
FILTER_FLAG_HOST_REQUIRED - requires the URL to contain the hostname (such as http://www.example.com)
FILTER_FLAG_PATH_REQUIRED - requires the URL to have a path after the domain name (such as www.example.com/example1/test2/)
FILTER_FLAG_QUERY_REQUIRED - requires a query string to exist in the URL (such as "example.php?name=Peter&age=37")
<?php$url = "http://www.example.com";if(!filter_var($url, FILTER_VALIDATE_URL)) { echo "URL is not valid"; }else { echo "URL is valid"; }? >
The output of the code looks like this:
URL is valid
<?php$url = "example.php?name=Peter&age=37";if(!filter_var($url, FILTER_VALIDATE_URL,FILTER_FLAG_QUERY_REQUIRED)) { echo "URL is not valid"; }else { echo "URL is valid"; }?>
The output of the code looks like this:
URL is valid