bentools/querystring

Query String manipulation library. PHP 7.1+. No dependency, immutable, PSR-7 compliant.

Maintainers

👁 bpolaszek

Package info

github.com/bpolaszek/querystring

pkg:composer/bentools/querystring

Statistics

Installs: 41 373

Dependents: 8

Suggesters: 0

Stars: 13

Open Issues: 0

1.3.1 2024-12-05 15:38 UTC

Requires

  • php: >=7.1

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT ac110126e9feef013fca99cc6b24e5ffd4f6473a

urluriquery stringquerystringpsr-7psr7

This package is auto-updated.

Last update: 2026-06-05 19:12:41 UTC


README

👁 Latest Stable Version
👁 License
👁 CI Workflow
👁 Coverage
👁 Quality Score
👁 Total Downloads

QueryString

A lightweight, object-oriented, Query String manipulation library.

Why?

Because I needed an intuitive way to add or remove parameters from a query string, in any project.

Oh, and, I also wanted that ['foos' => ['foo', 'bar']] resolved to foos[]=foo&foos[]=bar instead of foos[0]=foo&foos[1]=bar, unlike many libraries do.

Thanks to object-oriented design, you can define the way query strings are parsed and rendered.

Usage

Simple as that:

require_once __DIR__ . '/vendor/autoload.php';

use function BenTools\QueryString\query_string;

$qs = query_string(
 'foo=bar&baz=bat'
);
$qs = $qs->withParam('foo', 'foofoo')
 ->withoutParam('baz')
 ->withParam('ho', 'hi');

print_r($qs->getParams());
/* Array
(
 [foo] => foofoo
 [ho] => hi
) */

print $qs; // foo=foofoo&ho=hi

Documentation

Instantiation / Parsing

Manipulate parameters

Render as string

Installation

PHP 7.1+ is required.

composer require bentools/querystring:^1.0

Tests

./vendor/bin/phpunit

License

MIT

See also

bentools/uri-factory - A PSR-7 UriInterface factory based on your own dependencies.

bentools/pager - A simple, object oriented Pager.

bentools/where - A framework-agnostic fluent, immutable, SQL query builder.

bentools/picker - Pick a random item from an array, with weight management.

bentools/psr7-request-matcher - A PSR-7 request matcher interface.

bentools/cartesian-product - Generate all possible combinations from a multidimensionnal array.

bentools/string-combinations - A string combinations generator.

bentools/flatten-iterator - An iterator that flattens multiple iterators or arrays.