PHPackages                             filippo-toso/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. filippo-toso/uri

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

filippo-toso/uri
================

A simple class to easily manipulate URLs.

v1.0.8(1y ago)2698MITPHPPHP ^7.2 || ^8.0

Since Mar 13Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (10)Used By (0)

URI
===

[](#uri)

A simple class to easily manipulate URLs.

Requirements
------------

[](#requirements)

- PHP 7.2+

Installing
----------

[](#installing)

Use Composer to install it:

```
composer require filippo-toso/uri

```

Basic usage
-----------

[](#basic-usage)

You can create an instance of the URI class using the static `make()` or through its constructor:

```
use FilippoToso\URI\URI;

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

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

// or

$uri = new URI($url);

```

You can also pass other optional parameters that will be used when creating the querystring part of the URL. Check the source code for more details.

Once you have an instance of the class, you can use its fluent API to manipulate the URL as you like.

For instance, let's change the schema and domain:

```
use FilippoToso\URI\URI;

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

$newUrl = URI::make($url)
    ->scheme('https') // Changes the url to: https://www.example.com/dir/sub/file.php?name=john&emailjohn@smith.com
    ->domain('test.com') // Changes the url to: https://test.com/dir/sub/file.php?name=john&emailjohn@smith.com
    ->url();

```

You can call the following methods to get/set the relative parts of the URL: `scheme(), user(), pass(), host(), port(), path(), query() and fragment()`.

For instance, let's get the domain:

```
use FilippoToso\URI\URI;

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

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

```

The class can be casted to string to get the whole url or you can use the `url()` method as shown above. You can also get the unmodified url using the `original()` method.

More complex usage
------------------

[](#more-complex-usage)

Now let's do something more complex, for instance, let's change an url through a relative path.

```
use FilippoToso\URI\URI;

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

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

$newUrl = URI::make($url)
    ->relative($relativeUrl) // Changes the url to: http://www.example.com/hello.php?name=john&emailjohn@smith.com
    ->url();

```

The parameter passed to the `relative()` method can be a full URL (in this case the whole URL will be replaced with the new one), an absolute path or a relative path. It can also include the querystring and the fragment.

You can also change only the extension of the file using the `extension()` method or replace the querystring using the `params()` method (it accepts an array of parameters as input) or the `query()` (it accepts a string as input).

Querystring manipulation
------------------------

[](#querystring-manipulation)

Talking about querystring manipulation, there are other useful methods to do that. For instance, you can use:

- `add()` to add a parameter
- `remove()` to remove a parameter
- `set()` to replace the parameter value
- `get()` to get the parameter value

All these methods accept a dot notation as the key name. For instance, to change the a parameter like `$_GET['post']['content']['html']` you will use the dot notation `post.content.html`.

Talking about the `remove()` method, instead of a key, you can pass it a callback to remove multiple elements in one go. For instance, here's the code to remove all the `utm_*` parameters used to track campaigns in Google Analytics:

```
$url = 'https://www.example.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();

```

That's it, go change the URLs!.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance49

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~150 days

Recently: every ~244 days

Total

9

Last Release

376d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/55d89f2d44fb12225de2119994028ee69e36770bcf33c2b1ddf0d6672d28151b?d=identicon)[filippo.toso](/maintainers/filippo.toso)

---

Top Contributors

[![filippotoso](https://avatars.githubusercontent.com/u/26958813?v=4)](https://github.com/filippotoso "filippotoso (9 commits)")

### Embed Badge

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

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

###  Alternatives

[symfony/polyfill-php82

Symfony polyfill backporting some PHP 8.2+ features to lower PHP versions

6651.6M102](/packages/symfony-polyfill-php82)[ddoe/wysiwyg-editor-module

Summernote WYSIWYG Editor for OXID eShop.

191.0M5](/packages/ddoe-wysiwyg-editor-module)[tcb13/substringy

A sub string manipulation library with multibyte support that extends Stringy

1761.0k1](/packages/tcb13-substringy)

PHPackages © 2026

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