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(10mo ago)2647MITPHPPHP ^7.2 || ^8.0

Since Mar 13Pushed 10mo 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 1mo ago

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 83% of packages

Maintenance53

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Recently: every ~244 days

Total

9

Last Release

329d 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

[php-forge/foxy

Fast, reliable, and secure Bun/NPM/Yarn/pnpm bridge for Composer

45103.3k4](/packages/php-forge-foxy)[cytopia/check_git

Nagios plugin to verify a git repository.

105.2k](/packages/cytopia-check-git)[demi/seo

Library for working with SEO parameters of models

131.6k](/packages/demi-seo)

PHPackages © 2026

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