prinx / url
URL utilities for PHP
v1.0.0
2021-07-09 09:05 UTC
Requires (Dev)
- phpunit/phpunit: ^9.5
README
URL utilities for PHP
Installation
composer require prinx/url
Usage
Create an instance of the utility class
$url = new \Prinx\Url;
Add query string to URL
$newUrl = $url->addQueryString('https://test.com', ['action' => 'test']); // https://test.com?action=test $newUrl = $url->addQueryString('https://test.com?name=url', ['action' => 'test']); // https://test.com?name=url&action=test
Get URL parts
$urlParts = $url->getParts('https://test.com?name=url'); /* [ 'scheme' => 'https' 'host' => 'test.com' 'path' => '/path/' 'query' => 'query=string&action=test&name=url' ] */
$urlParts = $url->getParts('https://user:password@test.com:85/path/?action=test&name=url#faq'); /* [ 'scheme' => 'https' 'host' => 'test.com' 'port' => 85 'user' => 'user' 'pass' => 'password' 'path' => '/path/' 'query' => 'action=test&name=url' 'fragment' => 'faq' ] */
Get query string
$queryStrings = $url->getQueryStrings('https://test.com?name=url&action=test'); // ['name' => 'url', 'action' => 'test']
Remove query string from URL
$newUrl = $url->removeQueryString('https://test.com?name=url&action=test', 'name'); // https://test.com?action=test
$newUrl = $url->removeQueryString('https://test.com?name=url&action=test', ['name', 'action']); // https://test.com
Contribute
Star ⭐ the repo, fork it, fix a bug, add a new feature, write tests, correct documentation, and submit a pull request.