function drupal_parse_url


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
cis7 drupal_parse_url($url)
cle7 drupal_parse_url($url)
elmsmedia7 drupal_parse_url($url)
icor7 drupal_parse_url($url)
meedjum_blog7 drupal_parse_url($url)
mooc7 drupal_parse_url($url)

Parses a system URL string into an associative array suitable for url().

This function should only be used for URLs that have been generated by the system, such as via url(). It should not be used for URLs that come from external sources, or URLs that link to external resources.

The returned array contains a 'path' that may be passed separately to url(). For example:

  $options = drupal_parse_url($_GET['destination']);
  $my_url = url($options['path'], $options);
  $my_link = l('Example link', $options['path'], $options);

This is required, because url() does not support relative URLs containing a query string or fragment in its $path argument. Instead, any query string needs to be parsed into an associative query parameter array in $options['query'] and the fragment into $options['fragment'].


$url: The URL string to parse, f.e. $_GET['destination'].

Return value

An associative array containing the keys:

  • 'path': The path of the URL. If the given $url is external, this includes the scheme and host.
  • 'query': An array of query parameters of $url, if existent.
  • 'fragment': The fragment of $url, if existent.

See also



Related topics

7 calls to drupal_parse_url()
confirm_form in modules/system/system.module
Generates a form array for a confirmation form.
ctools_jump_menu_submit in sites/all/modules/ulmus/ctools/includes/
Submit handler for the jump menu.
drupal_goto in includes/
Sends the user to a different page.
field_ui_get_destinations in modules/field_ui/
Extracts next redirect path from an array of multiple destinations.
file_entity_edit in sites/all/modules/ulmus/file_entity/
Page callback: Form constructor for the file edit form.

... See full list


includes/, line 580
Common functions that many Drupal modules will need to reference.


function drupal_parse_url($url) {
  $options = array(
    'path' => NULL,
    'query' => array(),
    'fragment' => '',

  // External URLs: not using parse_url() here, so we do not have to rebuild
  // the scheme, host, and path without having any use for it.
  if (strpos($url, '://') !== FALSE) {
    // Split off everything before the query string into 'path'.
    $parts = explode('?', $url);
    $options['path'] = $parts[0];
    // If there is a query string, transform it into keyed query parameters.
    if (isset($parts[1])) {
      $query_parts = explode('#', $parts[1]);
      parse_str($query_parts[0], $options['query']);
      // Take over the fragment, if there is any.
      if (isset($query_parts[1])) {
        $options['fragment'] = $query_parts[1];
  // Internal URLs.
  else {
    // parse_url() does not support relative URLs, so make it absolute. E.g. the
    // relative URL "foo/bar:1" isn't properly parsed.
    $parts = parse_url('' . $url);
    // Strip the leading slash that was just added.
    $options['path'] = substr($parts['path'], 1);
    if (isset($parts['query'])) {
      parse_str($parts['query'], $options['query']);
    if (isset($parts['fragment'])) {
      $options['fragment'] = $parts['fragment'];
  // The 'q' parameter contains the path of the current page if clean URLs are
  // disabled. It overrides the 'path' of the URL when present, even if clean
  // URLs are enabled, due to how Apache rewriting rules work.
  if (isset($options['query']['q'])) {
    $options['path'] = $options['query']['q'];

  return $options;