1. Go to this page and download the library: Download fabgg/url-search-params library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fabgg / url-search-params example snippets
// Include dependencies installed with composer
new URLSearchParams('?q=github');
$search->merge(['user'=>'fabrice'])
echo $search->toString();
$search = new URLSearchParams('?q=github+web+site&u=yan');
// equivalent to:
$search = new URLSearchParams(['q' => 'github web site', 'u' => 'yan']);
$search= new URLSearchParams();
// array
search->append(["id"=> 1]);
$search = new URLSearchParams();
// key and value
$search->appendTp("id"=> 1);
// value can be an array
$search->appendTp("id"=> [3,5,7]);
echo (string)$search;
// result is `?id=1&id=3&id=5&id=7`
$search.delete("id");
$search.get("id");
// return an array [1, 3, 5, 7]
$search = new URLSearchParams('?q=github&u=yan');
// all query parameters are
$search.getAll();
// return ['q' => ['github'], 'u' => ['yan']]
$search.getAll("q");
// return ['q' => ['github']] like $search->get('q')