--- layout: default title: URI Query string parser redirect_from: - /query-parser/ --- Uri Query String Parser and Builder ======= [](https://travis-ci.org/thephpleague/uri-query-parser) [](https://github.com/thephpleague/uri-query-parser/releases) This package contains a userland PHP uri query parser and builder. ```php = 7.2** but the latest stable version of PHP is recommended Installation -------- ```bash $ composer require league/uri-query-parser ``` Usage --------
## Parsing the URI query string Parsing a query string is easy. ```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\Parser\InvalidUriComponent` marker class which extends PHP's `InvalidArgumentException` class. - If the query string is invalid a `League\Uri\Exception\MalformedUriComponent` exception is thrown. - If the query pair is invalid a `League\Uri\Parser\InvalidQueryPair` exception is thrown. - If the encoding algorithm is unknown or invalid a `League\Uri\Parser\UnknownEncoding` exception is thrown. ```php