PHP code example of codeinc / url
1. Go to this page and download the library: Download codeinc/url 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/ */
codeinc / url example snippets
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/):