PHP code example of markocupic / url-util
1. Go to this page and download the library: Download markocupic/url-util 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/ */
markocupic / url-util example snippets
class DemoController
{
public function index(UrlUtil $urlUtil)
{
// Current request URL: https://example.com/page?foo=bar
// Add a single query parameter
$newUrl = $urlUtil->addQueryParam('foo_one', 'bar');
// Result: https://example.com/page?foo_one=bar
// Add an array parameter
$newUrl = $urlUtil->addQueryParams('foo_two', 'biz,buz'], $newUrl);
// Result: https://example.com/page?foo_one=bar&foo_two[]=biz&foo_two[]=buz
// Remove one or more query parameters
$url = 'https://example.com/page?foo=bar&baz=qux';
$newUrl = $urlUtil->removeQueryParam(['foo'], $url);
// Result: https://example.com/page?baz=qux
}
}