Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HeaderUtils.php

function HeaderUtils::parseQuery

Like parse_str(), but preserves dots in variable names.

1 call to HeaderUtils::parseQuery()
Request::normalizeQueryString in vendor/symfony/http-foundation/Request.php
Normalizes a query string.

File

vendor/symfony/http-foundation/HeaderUtils.php, line 201

Class

HeaderUtils
HTTP header utility functions.

Namespace

Symfony\Component\HttpFoundation

Code

public static function parseQuery(string $query, bool $ignoreBrackets = false, string $separator = '&') : array {
    $q = [];
    foreach (explode($separator, $query) as $v) {
        if (false !== ($i = strpos($v, "\x00"))) {
            $v = substr($v, 0, $i);
        }
        if (false === ($i = strpos($v, '='))) {
            $k = urldecode($v);
            $v = '';
        }
        else {
            $k = urldecode(substr($v, 0, $i));
            $v = substr($v, $i);
        }
        if (false !== ($i = strpos($k, "\x00"))) {
            $k = substr($k, 0, $i);
        }
        $k = ltrim($k, ' ');
        if ($ignoreBrackets) {
            $q[$k][] = urldecode(substr($v, 1));
            continue;
        }
        if (false === ($i = strpos($k, '['))) {
            $q[] = bin2hex($k) . $v;
        }
        else {
            $q[] = bin2hex(substr($k, 0, $i)) . rawurlencode(substr($k, $i)) . $v;
        }
    }
    if ($ignoreBrackets) {
        return $q;
    }
    parse_str(implode('&', $q), $q);
    $query = [];
    foreach ($q as $k => $v) {
        if (false !== ($i = strpos($k, '_'))) {
            $query[substr_replace($k, hex2bin(substr($k, 0, $i)) . '[', 0, 1 + $i)] = $v;
        }
        else {
            $query[hex2bin($k)] = $v;
        }
    }
    return $query;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal