valid_url

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 valid_url($url, $absolute = FALSE)

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. Valid values per RFC 3986.

Übergabeparameter

$url The URL to verify.

$absolute Whether the URL is absolute (beginning with a scheme such as "http:").

Rückgabewert

TRUE if the URL is in a valid format.

Verwandte Themen

▾ 9 functions call valid_url()

aggregator_form_feed_validate in modules/aggregator/aggregator.admin.inc
Validate aggregator_form_feed() form submissions.
aggregator_form_opml_submit in modules/aggregator/aggregator.admin.inc
Process aggregator_form_opml form submissions.
aggregator_form_opml_validate in modules/aggregator/aggregator.admin.inc
Validate aggregator_form_opml form submissions.
comment_validate in modules/comment/comment.module
Validate comment data.
profile_validate_profile in modules/profile/profile.module
ValidUrlTestCase::testInvalidAbsolute in modules/simpletest/tests/common.test
Test invalid absolute urls.
ValidUrlTestCase::testInvalidRelative in modules/simpletest/tests/common.test
Test invalid relative urls.
ValidUrlTestCase::testValidAbsolute in modules/simpletest/tests/common.test
Test valid absolute urls.
ValidUrlTestCase::testValidRelative in modules/simpletest/tests/common.test
Test valid relative urls.

Code

includes/common.inc, line 1189

<?php
function valid_url($url, $absolute = FALSE) {
  if ($absolute) {
    return (bool) preg_match("
      /^                                                      # Start at the beginning of the text
      (?:ftp|https?):\/\/                                     # Look for ftp, http, or https schemes
      (?:                                                     # Userinfo (optional) which is typically
        (?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)*      # a username or a username and password
        (?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@          # combination
      )?
      (?:
        (?:[a-z0-9\-\.]|%[0-9a-f]{2})+                        # A domain name or a IPv4 address
        |(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\])         # or a well formed IPv6 address
      )
      (?::[0-9]+)?                                            # Server port number (optional)
      (?:[\/|\?]
        (?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})   # The path and query (optional)
      *)?
    $/xi", $url);
  }
  else {
    return (bool) preg_match("/^(?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})+$/i", $url);
  }
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen