function valid_url in Drupal 4
Same name and namespace in other branches
- 5 includes/common.inc \valid_url()
- 6 includes/common.inc \valid_url()
- 7 includes/common.inc \valid_url()
Verify the syntax of the given URL.
Parameters
$url: The URL to verify.
$absolute: Whether the URL is absolute (beginning with a scheme such as "http:").
Return value
TRUE if the URL is in a valid format.
Related topics
4 calls to valid_url()
- comment_validate in modules/
comment.module - path_form_validate in modules/
path.module - Verify that URL alias is valid.
- path_nodeapi in modules/
path.module - Implementation of hook_nodeapi().
- profile_validate_profile in modules/
profile.module
File
- includes/
common.inc, line 670 - Common functions that many Drupal modules will need to reference.
Code
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);
}
}