drupal_http_build_query

Versions
7
drupal_http_build_query(array $query, $parent = '')

Parse an array into a valid, rawurlencoded query string.

This differs from http_build_query() as we need to rawurlencode() (instead of urlencode()) all query parameters.

See also

drupal_get_query_parameters()

Parameters

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

$parent Internal use only. Used to build the $query array key for nested items.

Return value

A rawurlencoded string which can be used as or appended to the URL query string.

Related topics

▾ 5 functions call drupal_http_build_query()

drupal_get_destination in includes/common.inc
Prepare a 'destination' URL query parameter for use in combination with drupal_goto().
drupal_http_build_query in includes/common.inc
Parse an array into a valid, rawurlencoded query string.
install_redirect_url in ./install.php
Return the URL that should be redirected to during an installation request.
shortcut_page_build in modules/shortcut/shortcut.module
Implements hook_page_build().
url in includes/common.inc
Generate a URL.

Code

includes/common.inc, line 487

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

  foreach ($query as $key => $value) {
    $key = ($parent ? $parent . '[' . rawurlencode($key) . ']' : rawurlencode($key));

    // Recurse into children.
    if (is_array($value)) {
      $params[] = drupal_http_build_query($value, $key);
    }
    // If a query parameter value is NULL, only append its key.
    elseif (!isset($value)) {
      $params[] = $key;
    }
    else {
      // For better readability of paths in query strings, we decode slashes.
      // @see drupal_encode_path()
      $params[] = $key . '=' . str_replace('%2F', '/', rawurlencode($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.