A PHP 7 library to manipulates URLs. This library is compatible with PSR-7 UriInterface
through the Psr7Url
and [Psr7ServerUrl
] classes.
<?php
use CodeInc\Url\Url;
// parsing a URL
$url = Url::fromString("https://www.google.com/?q=A+great+search");
if (isset($url->getQueryAsArray()["p"])) {
echo $url->getQueryAsArray()["p"];
}
// building a URL
$url = (new Url())
->withHost("www.google.com")
->withoutScheme("https")
->withQuery(["q", "A great search"]);
echo $url;
// getting the current URL
$currentUrl = Url::fromGlobals();
## Tests
A unit test is available for the [`Url`](src/Url.php) class in the [`UrlTest`](tests/UrlTest.php) class.
To run the tests using [PHPUnit](https://phpunit.de/):
```bash
./vendor/bin/phpunit tests/UrlTest.php
This library is available through Packagist and can be installed using Composer:
composer require codeinc/url
The library is published under the MIT license (see LICENSE
file).