https://github.com/bpolaszek/querystring
PHP 7.1+ Query String manipulation library. No dependency, immutable, lightweight, PSR-7 compliant.
https://github.com/bpolaszek/querystring
immutable lightweight php php7 php71 psr-7 querystring uri url
Last synced: 16 days ago
JSON representation
PHP 7.1+ Query String manipulation library. No dependency, immutable, lightweight, PSR-7 compliant.
- Host: GitHub
- URL: https://github.com/bpolaszek/querystring
- Owner: bpolaszek
- License: mit
- Created: 2017-11-08T16:14:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-12-05T15:39:44.000Z (5 months ago)
- Last Synced: 2025-03-23T21:52:03.771Z (about 1 month ago)
- Topics: immutable, lightweight, php, php7, php71, psr-7, querystring, uri, url
- Language: PHP
- Homepage:
- Size: 44.9 KB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://packagist.org/packages/bentools/querystring)
[](https://packagist.org/packages/bentools/querystring)
[](https://github.com/bpolaszek/querystring/actions/workflows/ci-workflow.yml)
[](https://codecov.io/gh/bpolaszek/querystring)
[](https://scrutinizer-ci.com/g/bpolaszek/querystring)
[](https://packagist.org/packages/bentools/querystring)# 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](doc/Instantiation.md) and [rendered](doc/RenderAsString.md#change-renderer).
## Usage
Simple as that:
```php
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](doc/Instantiation.md)
[Manipulate parameters](doc/ManipulateParameters.md)
[Render as string](doc/RenderAsString.md)
## Installation
PHP 7.1+ is required.
> composer require bentools/querystring:^1.0## Tests
> ./vendor/bin/phpunit## License
MIT## See also
[bentools/uri-factory](https://github.com/bpolaszek/uri-factory) - A PSR-7 `UriInterface` factory based on your own dependencies.
[bentools/pager](https://github.com/bpolaszek/bentools-pager) - A simple, object oriented Pager.
[bentools/where](https://github.com/bpolaszek/where) - A framework-agnostic fluent, immutable, SQL query builder.
[bentools/picker](https://github.com/bpolaszek/picker) - Pick a random item from an array, with weight management.
[bentools/psr7-request-matcher](https://github.com/bpolaszek/psr7-request-matcher) - A PSR-7 request matcher interface.
[bentools/cartesian-product](https://github.com/bpolaszek/cartesian-product) - Generate all possible combinations from a multidimensionnal array.
[bentools/string-combinations](https://github.com/bpolaszek/string-combinations) - A string combinations generator.
[bentools/flatten-iterator](https://github.com/bpolaszek/flatten-iterator) - An iterator that flattens multiple iterators or arrays.