codeinc/url

URL manipulation library

1.5.4 2018-12-05 11:22 UTC

This package is auto-updated.

Last update: 2024-11-06 09:49:04 UTC


README

A PHP 7 library to manipulates URLs. This library is compatible with PSR-7 UriInterface through the Psr7Url and [Psr7ServerUrl] classes.

Usage

<?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

Installation

This library is available through Packagist and can be installed using Composer:

composer require codeinc/url

License

The library is published under the MIT license (see LICENSE file).