Professional Documents
Culture Documents
Sanitize and Validate a URL copy
Sanitize and Validate a URL copy
Sanitize and Validate a URL copy
The following example uses the filter_var() function to first remove all illegal
characters from a URL, then check if $url is a valid URL:
Example
<?php
$url = "http://www.vu.edu.pk";
// Validate url
if (!filter_var($url, FILTER_VALIDATE_URL) === false) {
echo("$url is a valid URL");
} else {
echo("$url is not a valid URL");
}
?>