--- layout: default title: URI Query string parser --- Parse & Build a Query ======= The `League\Uri\Components\QueryString` is a userland PHP URI query parser and builder. ```php The parsing/building algorithms preserve pairs order and uses the same algorithm used by JavaScript UrlSearchParams
## Parsing the URI query string Parsing a query string is easy. ```php $pairs = QueryString::parse('module=home&action=show&page=😓'); // returns [ // ['module', 'home'], // ['action', 'show'], // ['page', '😓'] // ]; ``` ### Description ```php The$separator
argument can not be the empty string.
## Building the URI query string
To convert back the collection of key/value pairs into a valid query string or the `null` value you can use the static public `QueryString::build` method.
```php
The $separator
argument can not be the empty string.
## Extracting PHP variables
```php
[
// 1 => 'sid',
// ],
// 'arr test' => [
// 4 => [
// 'two' => 'fred',
// ]
// ],
// ' module ' => 'hide',
// ];
parse_str($query, $variables);
// $variables contains [
// 'module' = 'show',
// 'arr_test' => [
// 1 => 'sid',
// 4 => [
// 'two' => 'fred',
// ],
// ],
// 'module_' = 'hide',
// ];
```
## Exceptions
All exceptions extends the `League\Uri\Exceptions\UriException` marker class which extends PHP's `Throwable` class.
```php