Documentation for crwlr / query-string (v1.0)

Getting Started

This library provides a very convenient API to create, access and manipulate query strings used in HTTP GET (as part of the URL) or POST (as part of the body) requests.

If you need to work with query strings as part of URLs, you should use the url package. Its queryString() method uses this package under the hood.

Example Usage

use Crwlr\QueryString\Query;

$queryString = Query::fromString('foo[bar]=1&foo[baz]=2');

// Or creating the same query from array:

$queryString = Query::fromArray(['foo' => ['bar' => '1', 'baz' => '2']]);

if (!$queryString->get('foo')->has('quz')) {
    $queryString->appendTo('foo', ['quz' => '3']);
}

var_dump($queryString->toString());

// string(44) "foo%5Bbar%5D=1&foo%5Bbaz%5D=2&foo%5Bquz%5D=3"

var_dump($queryString->toArray());

// array(1) {
//     ["foo"]=>
//   array(3) {
//         ["bar"]=>
//     string(1) "1"
//         ["baz"]=>
//     string(1) "2"
//         ["quz"]=>
//     string(1) "3"
//   }
// }

Requirements

Requires PHP version 8.0 or above.

Installation

Install the latest version with:

composer require crwlr/query-string