PHPackages                             chroma-x/url-util - 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. chroma-x/url-util

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

chroma-x/url-util
=================

A PHP library providing common URL implementation.

2.0.7(5y ago)04.3k2MITPHPPHP &gt;=5.3

Since May 2Pushed 5y ago1 watchersCompare

[ Source](https://github.com/chroma-x/php-url-util)[ Packagist](https://packagist.org/packages/chroma-x/url-util)[ Docs](http://chroma-x.de/)[ RSS](/packages/chroma-x-url-util/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (2)

PHP URL Util
============

[](#php-url-util)

[![Build Status](https://camo.githubusercontent.com/8c04d662e76057fbf19c3d5267fa4ad37e604bdddc666c417c44480369b33f15/68747470733a2f2f7472617669732d63692e6f72672f6368726f6d612d782f7068702d75726c2d7574696c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/chroma-x/php-url-util)[![Test Coverage](https://camo.githubusercontent.com/f98d34ff410fd6c94a9b366b76ada7997086186044dab703634e4c067dfe8646/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6368726f6d612d782f7068702d75726c2d7574696c2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/chroma-x/php-url-util/coverage)[![Dependency Status](https://camo.githubusercontent.com/cf4b894ae1e4a2f0446d3e604f0a5a279e884c9cd29c20566b464eda25a573a1/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537323732666461613063613335303035303833663165362f62616467652e737667)](https://www.versioneye.com/user/projects/57272fdaa0ca35005083f1e6)[![SensioLabs Insight](https://camo.githubusercontent.com/4937f9e72f35b2129b2605ba24264d498d29553c97fc113d43436cdac474ccd6/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f64663233396563632d663333362d343636392d613031372d6663383236343937313135612e737667)](https://insight.sensiolabs.com/projects/df239ecc-f336-4669-a017-fc826497115a)[![Code Climate](https://camo.githubusercontent.com/0bdfdc575c2cc95428f292a26b3cd53858f83714f8bd3a11a47116616497a275/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6368726f6d612d782f7068702d75726c2d7574696c2f6261646765732f6770612e737667)](https://codeclimate.com/github/chroma-x/php-url-util)[![Latest Stable Version](https://camo.githubusercontent.com/a9eab02b817137cc498a23d4cea571fbd60f91d457c99fb23d23f78a69880d90/68747470733a2f2f706f7365722e707567782e6f72672f6368726f6d612d782f75726c2d7574696c2f762f737461626c65)](https://packagist.org/packages/chroma-x/url-util)[![Total Downloads](https://camo.githubusercontent.com/1876da36406c0371d3d323bd42999893ce7f6915857367b30997ea4a06bf696a/68747470733a2f2f706f7365722e707567782e6f72672f6368726f6d612d782f75726c2d7574696c2f646f776e6c6f616473)](https://packagist.org/packages/chroma-x/url-util)[![License](https://camo.githubusercontent.com/298ded67aa3dddbfdfc0a34f96f60ef944d9bc1388176c96eeb17edfdfb2b1dd/68747470733a2f2f706f7365722e707567782e6f72672f6368726f6d612d782f75726c2d7574696c2f6c6963656e7365)](https://packagist.org/packages/chroma-x/url-util)

A PHP library providing common URL implementation.

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

[](#installation)

```
{
   	"require": {
        "chroma-x/url-util": "~2.0"
    }
}

```

Usage
-----

[](#usage)

### Autoloading and namesapce

[](#autoloading-and-namesapce)

```
require_once('path/to/vendor/autoload.php');

```

### Parsing an URL

[](#parsing-an-url)

```
use ChromaX\UrlUtil;

$url = new UrlUtil\Url('https://john:secret@mydomain.com:8443/path/to/resource?arg1=123&arg2=test#fragment');

$scheme = $url->getScheme();
fwrite(STDOUT, 'Scheme "' . $scheme . '"' . PHP_EOL);

$hostname = $url->getHostname();
fwrite(STDOUT, 'Hostname "' . $hostname . '"' . PHP_EOL);

$port = $url->getPort();
fwrite(STDOUT, 'Port "' . (string)$port . '"' . PHP_EOL);

$username = $url->getUsername();
fwrite(STDOUT, 'Username "' . $username . '"' . PHP_EOL);

$password = $url->getPassword();
fwrite(STDOUT, 'Password "' . $password . '"' . PHP_EOL);

$path = $url->getPath();
fwrite(STDOUT, 'Path "' . $path . '"' . PHP_EOL);

$queryParameters = $url->getQueryParameters();
foreach ($queryParameters as $queryParameter) {
	fwrite(STDOUT, 'Query parameter "' . $queryParameter->getKey() . '" is "' . $queryParameter->getValue() . '"' . PHP_EOL);
}

$fragment = $url->getFragment();
fwrite(STDOUT, 'Fragment "' . $fragment . '"' . PHP_EOL);

$url
	->setScheme('http')
	->setHostname('yourdomain.com')
	->setPort(8080)
	->setUsername('doe')
	->setPassword('supersecret')
	->setPath('path/to/another/resource')
	->removeQueryParameterByKey('arg2')
	->addQueryParameter(new UrlUtil\QueryParameter('arg1', '456'))
	->addQueryParameter(new UrlUtil\QueryParameter('arg3', 'test'))
	->setFragment('target');

fwrite(STDOUT, 'URL "' . $url->buildUrl() . '"' . PHP_EOL);

```

will output the following

```
Scheme "https"
Hostname "mydomain.com"
Port "8443"
Username "john"
Password "secret"
Path "/path/to/resource"
Query parameter "arg1" is "123"
Query parameter "arg2" is "test"
Fragment "fragment"
URL "http://doe:supersecret@yourdomain.com:8080/path/to/another/resource?arg1=456&arg3=test#target"

```

---

Contribution
------------

[](#contribution)

Contributing to our projects is always very appreciated.
**But: please follow the contribution guidelines written down in the [CONTRIBUTING.md](https://github.com/chroma-x/php-url-util/blob/master/CONTRIBUTING.md) document.**

License
-------

[](#license)

PHP URL Util is under the MIT license.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

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

Recently: every ~413 days

Total

13

Last Release

1947d ago

Major Versions

1.0.4 → 2.0.02016-07-06

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5921241?v=4)[Martin Brecht-Precht](/maintainers/bonscho)[@Bonscho](https://github.com/Bonscho)

---

Tags

commoncomposer-packagephp-libraryurlurl

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chroma-x-url-util/health.svg)

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

###  Alternatives

[spatie/url

Parse, build and manipulate URL's

73914.3M97](/packages/spatie-url)[jbroadway/urlify

A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

6737.4M62](/packages/jbroadway-urlify)[league/uri-components

URI components manipulation library

31932.3M67](/packages/league-uri-components)[sabre/uri

Functions for making sense out of URIs.

29335.2M40](/packages/sabre-uri)[spomky-labs/base64url

Base 64 URL Safe Encoding/Decoding PHP Library

15439.5M49](/packages/spomky-labs-base64url)[misd/linkify

Converts URLs and email addresses in text into HTML links

1122.9M10](/packages/misd-linkify)

PHPackages © 2026

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