valid_url($url, $absolute = FALSE)
drupal/includes/common.inc, line 795
Verify the syntax of the given URL.
This function should only be used on actual URLs. It should not be used for Drupal menu paths, which can contain arbitrary characters.
$url The URL to verify.
$absolute Whether the URL is absolute (beginning with a scheme such as "http:").
TRUE if the URL is in a valid format.
| Name | Description |
|---|---|
| Input validation | Functions to validate user input. |
function valid_url($url, $absolute = FALSE) {
$allowed_characters = '[a-z0-9\/:_\-_\.\?\$,;~=#&%\+]';
if ($absolute) {
return preg_match("/^(http|https|ftp):\/\/". $allowed_characters ."+$/i", $url);
}
else {
return preg_match("/^". $allowed_characters ."+$/i", $url);
}
}