PHPackages                             ulthon/uri - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ulthon/uri

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ulthon/uri
==========

一个简单地解析和操作URI的类库

v1.0.2(1mo ago)013[1 issues](https://github.com/augushong/uri/issues)MulanPSL-2.0PHP

Since Oct 22Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/augushong/uri)[ Packagist](https://packagist.org/packages/ulthon/uri)[ RSS](/packages/ulthon-uri/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (4)Used By (0)

uri
===

[](#uri)

#### 介绍

[](#介绍)

一个简单地解析和操作URL的类库

最低支持php7.2，通过composer安装：

```
composer require ulthon/uri
```

基本的使用方式如下，通过`make`静态方法或手动实例化：

```
use Ulthon\URI\URI;

$url = 'https://phpreturn.com/index/a6310ae8e7c561.html?name=john&emailjohn@smith.com#fragment';

$uri = URI::make($url);

// 或者

$uri = new URI($url);
```

实例化完成之后，就可以使用类库方法随心所欲的操作URL。

比如设置协议或域名：

```
use Ulthon\URI\URI;

$url = 'phpreturn.com?name=john&emailjohn@smith.com';

$newUrl = URI::make($url)
    ->scheme('http') // 修改链接为: http://phpreturn.com/index/a6310ae8e7c561.html?name=john&emailjohn@smith.com
    ->domain('doc.ulthon.com') // 修改链接为: http://doc.ulthon.com/index/a6310ae8e7c561.html?name=john&emailjohn@smith.com
    ->url();
```

支持的方法如下：

- scheme()
- user()
- pass()
- host()
- port()
- path()
- query()
- fragment()

如果传入参数，就是设置，否则只是读取。比如我们要读取域名：

```
use Ulthon\URI\URI;

$url = 'http://phpreturn.com?name=john&emailjohn@smith.com';

$domain = URI::make($url)
    ->domain();
```

他还支持更复杂的用法，比如解析相对路径：

```
use Ulthon\URI\URI;

$url = 'http://phpreturn.com/dir/sub/file.php?name=john&emailjohn@smith.com';

$relativeUrl = '../../hello.php';

$newUrl = URI::make($url)
    ->relative($relativeUrl) // 链接修改为: http://phpreturn.com/hello.php?name=john&emailjohn@smith.com
    ->url();
```

在设置和获取query时，支持通过点分隔符读取多级数组，比如想要获取这样的值`$_GET['post']['content']['html']` ,这时只需要使用`post.content.html`即可获取。

query的操作有这些：

- `add()` 添加get参数
- `remove()` 删除get参数
- `set()` 设置get参数
- `get()` 读取get参数

其中remove方法支持通过回调函数方式：

```
$url = 'https://phpreturn.com/?utm_source=summer-mailer&utm_medium=email&utm_campaign=summer-sale';

$newUrl = URI::make($url)->remove(function ($key, $value) {
    return (bool)preg_match('#^utm_#si', $key);
})->url();
```

这样一个库，很简单，却很好用，提升开发幸福感。

基于
--

[](#基于)

本项目基于  项目开发，增加了更灵活的用法。

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance93

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~657 days

Total

3

Last Release

36d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c38618939a95a754cfb2dcc86ad65b11208047d75e7f66c5ea2d793425bb7885?d=identicon)[augushong](/maintainers/augushong)

---

Top Contributors

[![augushong](https://avatars.githubusercontent.com/u/31880431?v=4)](https://github.com/augushong "augushong (2 commits)")

### Embed Badge

![Health badge](/badges/ulthon-uri/health.svg)

```
[![Health](https://phpackages.com/badges/ulthon-uri/health.svg)](https://phpackages.com/packages/ulthon-uri)
```

###  Alternatives

[florianwolters/component-util-singleton

The Singleton (and Registry of Singletons a.k.a. Multiton) design pattern as a PHP component.

13179.3k5](/packages/florianwolters-component-util-singleton)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
