codeinc/url

URL操作库

1.5.4 2018-12-05 11:22 UTC

This package is auto-updated.

Last update: 2024-09-06 09:22:47 UTC


README

这是一个用于操作URL的PHP 7库。此库通过PSR-7 UriInterfacePsr7UrlPsr7ServerUrl类兼容。

用法

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

安装

此库可通过Packagist获取,并可以使用Composer进行安装。

composer require codeinc/url

许可证

该库在MIT许可证下发布(请参阅LICENSE文件)。