drupal_query_string_encode

Versions
4.7 – 6
drupal_query_string_encode($query, $exclude = array(), $parent = '')

Parse an array into a valid urlencoded query string.

Parameters

$query The array to be processed e.g. $_GET

$exclude The array filled with keys to be excluded. Use parent[child] to exclude nested items.

$parent Should not be passed, only used in recursive calls

Return value

urlencoded string which can be appended to/as the URL query string

▾ 5 functions call drupal_query_string_encode()

drupal_get_destination in includes/common.inc
Prepare a destination query string for use in combination with drupal_goto(). Used to direct the user back to the referring page after completing a form. By default the current URL is returned. If a destination exists in the previous request, that...
drupal_query_string_encode in includes/common.inc
Parse an array into a valid urlencoded query string.
pager_get_querystring in includes/pager.inc
Compose a query string to append to pager requests.
tablesort_get_querystring in includes/tablesort.inc
Compose a query string to append to table sorting requests.
theme_pager_link in includes/pager.inc
Format a link to a specific query result page.

Code

includes/common.inc, line 172

<?php
function drupal_query_string_encode($query, $exclude = array(), $parent = '') {
  $params = array();

  foreach ($query as $key => $value) {
    $key = drupal_urlencode($key);
    if ($parent) {
      $key = $parent .'['. $key .']';
    }

    if (in_array($key, $exclude)) {
      continue;
    }

    if (is_array($value)) {
      $params[] = drupal_query_string_encode($value, $exclude, $key);
    }
    else {
      $params[] = $key .'='. drupal_urlencode($value);
    }
  }

  return implode('&', $params);
}
?>
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.