valid_url

Versions
4.6 – 7
valid_url($url, $absolute = FALSE)

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 functions call valid_url()

comment_validate_form in modules/comment.module
path_nodeapi in modules/path.module
Implementation of hook_nodeapi().
path_save in modules/path.module
Verify that a new URL alias is valid, and save it to the database.
profile_validate_profile in modules/profile.module

Code

includes/common.inc, line 584

<?php
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);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.