PHPackages                             codeinc/url - 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. codeinc/url

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

codeinc/url
===========

A PHP library for URL manipulation, compatible with PSR-7 UriInterface

2.0.1(1mo ago)0330[1 PRs](https://github.com/CodeIncHQ/Url/pulls)1MITPHPPHP ^8.2CI passing

Since Dec 4Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/CodeIncHQ/Url)[ Packagist](https://packagist.org/packages/codeinc/url)[ Docs](https://github.com/codeinchq/url)[ RSS](/packages/codeinc-url/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (10)Dependencies (4)Versions (27)Used By (1)

codeinc/url
===========

[](#codeincurl)

[![Tests](https://github.com/codeinchq/url/actions/workflows/tests.yml/badge.svg)](https://github.com/codeinchq/url/actions/workflows/tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/679d7e5cc3d1718e423176be809b848c9fe36ca775463b01640354afb1129581/68747470733a2f2f706f7365722e707567782e6f72672f636f6465696e632f75726c2f762f737461626c65)](https://packagist.org/packages/codeinc/url)[![PHP](https://camo.githubusercontent.com/f3d2157ea06285f0a69e971860223415a12476f389d3e4a1ea3212300a26c6cc/68747470733a2f2f706f7365722e707567782e6f72672f636f6465696e632f75726c2f726571756972652f706870)](https://packagist.org/packages/codeinc/url)[![Total Downloads](https://camo.githubusercontent.com/dd5ae134b80fa7dfc657354c6da25877c7d0c2f46f1da94a1a0b02fa2936a70b/68747470733a2f2f706f7365722e707567782e6f72672f636f6465696e632f75726c2f646f776e6c6f616473)](https://packagist.org/packages/codeinc/url)[![License](https://camo.githubusercontent.com/aeeb7db96c1bf8e58c363738810daf5a4e53119e7ce2098e08ffb6b80e9a9fcd/68747470733a2f2f706f7365722e707567782e6f72672f636f6465696e632f75726c2f6c6963656e7365)](https://packagist.org/packages/codeinc/url)

A PHP library for URL manipulation, implementing [PSR-7](https://www.php-fig.org/psr/psr-7/) `UriInterface`.

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

[](#requirements)

- PHP 8.2+

Installation
------------

[](#installation)

```
composer require codeinc/url
```

Usage
-----

[](#usage)

### Parsing a URL

[](#parsing-a-url)

```
use CodeInc\Url\Url;

$url = Url::fromString('https://www.example.com/search?q=php&page=1#results');

$url->getScheme();       // 'https'
$url->getHost();         // 'www.example.com'
$url->getPath();         // '/search'
$url->getQuery();        // 'q=php&page=1'
$url->getQueryAsArray(); // ['q' => 'php', 'page' => '1']
$url->getFragment();     // 'results'
```

### Building a URL

[](#building-a-url)

```
$url = (new Url())
    ->withScheme('https')
    ->withHost('api.example.com')
    ->withPath('/v2/users')
    ->withQueryParams(['page' => '1', 'limit' => '50']);

echo $url; // https://api.example.com/v2/users?page=1&limit=50
```

### Modifying a URL

[](#modifying-a-url)

All `with*` methods return a new immutable instance:

```
$url = Url::fromString('https://example.com/path?a=1&b=2#frag');

$modified = $url
    ->withScheme('http')
    ->withQueryParams(['c' => '3'])
    ->withoutFragment();

echo $modified; // http://example.com/path?a=1&b=2&c=3
echo $url;      // https://example.com/path?a=1&b=2#frag (unchanged)
```

### Removing components

[](#removing-components)

```
$url->withoutScheme();
$url->withoutHost();
$url->withoutPort();
$url->withoutUserInfo();
$url->withoutPath();
$url->withoutFragment();
$url->withoutQuery();            // removes entire query string
$url->withoutQuery(['a', 'b']); // removes specific parameters
```

### PSR-7 interop

[](#psr-7-interop)

```
// From a PSR-7 UriInterface
$url = Url::fromPsr7Uri($psr7Uri);

// From a PSR-7 ServerRequestInterface
$url = Url::fromPsr7Request($serverRequest);

// Use anywhere a UriInterface is expected
function processUri(UriInterface $uri): void { /* ... */ }
processUri($url);
```

### Getting the current URL

[](#getting-the-current-url)

```
$url = Url::fromGlobals();
```

Tests
-----

[](#tests)

```
composer install
vendor/bin/phpunit
```

License
-------

[](#license)

This library is published under the MIT license (see [LICENSE](LICENSE) file).

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance94

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

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

Recently: every ~672 days

Total

25

Last Release

31d ago

Major Versions

1.5.4 → v2.0.x-dev2026-04-15

PHP version history (4 changes)1.0.0PHP &gt;=7.0

1.1.0PHP &gt;=7.2

1.3.2PHP &gt;=7.1

v2.0.x-devPHP ^8.2

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/8f72f949d7f70e400c02c225685f1934dec6219689f25edec38b4037df166d58?d=identicon)[codeinc](/maintainers/codeinc)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codeinc-url/health.svg)

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

###  Alternatives

[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

343121.4M79](/packages/google-cloud-core)[aimeos/aimeos-base

Aimeos base layer for abstracting from host environments

2.1k134.0k1](/packages/aimeos-aimeos-base)[phpgt/dom

Modern DOM API.

12412.2M18](/packages/phpgt-dom)[razorpay/ifsc

Razorpay IFSC Codes Library

382201.9k](/packages/razorpay-ifsc)[anthropic-ai/sdk

Anthropic PHP SDK

129134.7k5](/packages/anthropic-ai-sdk)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)

PHPackages © 2026

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