function drupal_http_build_query, function drupal_get_query_parameters

Public

https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_...

7 common.inc drupal_http_build_query(array $query, $parent = '')
Parses 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.

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.

See also

drupal_get_query_parameters()

Related topics

HTTP handling
Functions to properly handle HTTP responses.
PHP wrapper functions
Functions that are wrappers or custom implementations of PHP functions.
9 calls to drupal_http_build_query()
File

includes/common.inc, line 486
Common functions that many Drupal modules will need to reference.

Get raw version
php
  1. function drupal_http_build_query(array $query, $parent = '') {
  2. $params = array();
  3.  
  4. foreach ($query as $key => $value) {
  5. $key = ($parent ? $parent . '[' . rawurlencode($key) . ']' : rawurlencode($key));
  6.  
  7. // Recurse into children.
  8. if (is_array($value)) {
  9. $params [] = drupal_http_build_query($value, $key);
  10. }
  11. // If a query parameter value is NULL, only append its key.
  12. elseif (!isset($value)) {
  13. $params [] = $key;
  14. }
  15. else {
  16. // For better readability of paths in query strings, we decode slashes.
  17. $params [] = $key . '=' . str_replace('%2F', '/', rawurlencode($value));
  18. }
  19. }
  20.  
  21. return implode('&', $params);
  22. }

function drupal_get_query_parameters

https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_...

7 common.inc drupal_get_query_parameters(array $query = NULL, array $exclude = array('q'), $parent = '')
Processes a URL query parameter array to remove unwanted elements.

Parameters

$query: (optional) An array to be processed. Defaults to $_GET.

$exclude: (optional) A list of $query array keys to remove. Use "parent[child]" to exclude nested items. Defaults to array('q').

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

Return value

An array containing query parameters, which can be used for url().

Related topics

HTTP handling
Functions to properly handle HTTP responses.
11 calls to drupal_get_query_parameters()
File

includes/common.inc, line 417
Common functions that many Drupal modules will need to reference.

Get raw version
php
  1. function drupal_get_query_parameters(array $query = NULL, array $exclude = array('q'), $parent = '') {
  2. // Set defaults, if none given.
  3. if (!isset($query)) {
  4. $query = $_GET;
  5. }
  6. // If $exclude is empty, there is nothing to filter.
  7. if (empty($exclude)) {
  8. return $query;
  9. }
  10. elseif (!$parent) {
  11. $exclude = array_flip($exclude);
  12. }
  13.  
  14. $params = array();
  15. foreach ($query as $key => $value) {
  16. $string_key = ($parent ? $parent . '[' . $key . ']' : $key);
  17. if (isset($exclude [$string_key])) {
  18. continue;
  19. }
  20.  
  21. if (is_array($value)) {
  22. $params [$key] = drupal_get_query_parameters($value, $exclude, $string_key);
  23. }
  24. else {
  25. $params [$key] = $value;
  26. }
  27. }
  28.  
  29. return $params;
  30. }