PHPackages                             projectcleverweb/php-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. projectcleverweb/php-uri

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

projectcleverweb/php-uri
========================

A PHP library for working with URI's, that is designed around the URI standard. Requires PHP 5.4 or later. This library replaces and extends all of PHP's parse\_url() features, and even has some handy aliases.

1.0.0(11y ago)32721MITPHPPHP &gt;=5.4

Since Jul 28Pushed 11y ago2 watchersCompare

[ Source](https://github.com/ProjectCleverWeb/PHP-URI)[ Packagist](https://packagist.org/packages/projectcleverweb/php-uri)[ Docs](https://github.com/ProjectCleverWeb/PHP-URI)[ RSS](/packages/projectcleverweb-php-uri/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (6)Used By (1)

PHP URI [![Build Status](https://camo.githubusercontent.com/06692215a1ad251c4c6b57b1c5a5384562a64e736a75a7347d969befc76b33ed/68747470733a2f2f7472617669732d63692e6f72672f50726f6a656374436c657665725765622f5048502d5552492e7376673f6272616e63683d6d6173746572267374796c653d666c6174)](https://travis-ci.org/ProjectCleverWeb/PHP-URI) [![Code Coverage](https://camo.githubusercontent.com/9ec3b97d27d6530a780446d4bf85baffbc7d511cf0d62ca4dd7cf00736f068bc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50726f6a656374436c657665725765622f5048502d5552492f6261646765732f636f7665726167652e706e673f623d6d6173746572267374796c653d666c6174)](https://scrutinizer-ci.com/g/ProjectCleverWeb/PHP-URI/?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/d0f5906b56f069d4ddede0cbd0fec663791866be84c91e2e5e0b3c9d3a7b9e33/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50726f6a656374436c657665725765622f5048502d5552492f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572267374796c653d666c6174)](https://scrutinizer-ci.com/g/ProjectCleverWeb/PHP-URI/?branch=master) [![License](https://camo.githubusercontent.com/bc3cf7e497128f74c33ae0e381d34980d53b2dd777d5aa7b4ef543673f9a40ed/68747470733a2f2f706f7365722e707567782e6f72672f70726f6a656374636c657665727765622f7068702d7572692f6c6963656e73652e7376673f7374796c653d666c6174)](http://opensource.org/licenses/MIT)
===============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#php-uri----)

A PHP library for working with URI's, that is designed around the URI standard. Requires PHP `5.4` or later. This library replaces and extends all of PHP's `parse_url()` features, and even has some handy aliases.

Copyright (c) 2014 Nicholas Jordon - All Rights Reserved.

### Installing The Library

[](#installing-the-library)

#### Composer:

[](#composer)

Add this to your composer.json file

```
"require": {
	"projectcleverweb/php-uri":"~1.0"
}
```

#### Manual:

[](#manual)

**Download:**
[![Latest Stable Version](https://camo.githubusercontent.com/cb18e38d7717b113005730e23775bf5ae6e2eaa91ea8a542ca160df02586c9b9/68747470733a2f2f706f7365722e707567782e6f72672f70726f6a656374636c657665727765622f7068702d7572692f762f737461626c652e7376673f7374796c653d666c6174)](https://github.com/ProjectCleverWeb/PHP-URI/releases/tag/1.0.0) [![Latest Unstable Version](https://camo.githubusercontent.com/0ea3dc4516c0bafe740170e72e65e941042672798d564f54289440fffabb232a/68747470733a2f2f706f7365722e707567782e6f72672f70726f6a656374636c657665727765622f7068702d7572692f762f756e737461626c652e7376673f7374796c653d666c6174)](https://github.com/ProjectCleverWeb/PHP-URI/archive/master.zip)

Just include the `uri.lib.php` file somewhere in your application.

Examples
--------

[](#examples)

#### Example #1: String Operations

[](#example-1-string-operations)

```
$uri = new uri('http://example.com/path/to/file.ext');

$uri->replace('QUERY', 'number=3');
$uri->replace('PATH', '/foo/bar');
$uri->append('PATH', '.baz');
$new = $uri->prepend('HOST', 'www.');

$uri->reset();
$original = $uri->str();

$uri->replace('FRAGMENT', 'Checkout');
$secure = $uri->replace('SCHEME_NAME', 'https');

echo $new.PHP_EOL;
echo $original.PHP_EOL;
echo $secure;
```

**Output:**

```
http://www.example.com/foo/bar.baz?number=3
http://example.com/path/to/file.ext
https://example.com/path/to/file.ext#Checkout
```

#### Example #2: Daisy Chaining Operations

[](#example-2-daisy-chaining-operations)

Need to change a lot while keeping anything extra intact? Chain it.

```
$uri1 = new uri('ftp://jdoe:pass1234@my-server.com/public_html');

// Lets upgrade to an admin account under sftp, but stay in the current directory.
$uri1->chain()->
	prepend('SCHEME_NAME', 's')->
	replace('PORT', '22')->
	replace('USER', 'admin')->
	replace('PASS', 'secure-pass-123');

// NOTE: chain() methods always return the chain object, even if a method fails.
echo $uri1;

// Any failure results in the chain() error count geting incremented.
if (0 < $uri->chain()->error_count) {
	print_f('The chain failed %1$s times!', $uri->chain()->error_count);
}
```

**Output:**

```
sftp://admin:secure-pass-123@my-server.com:22/public_html
```

#### Example #3: Information Gathering

[](#example-3-information-gathering)

```
$uri = new uri('http://example.com/path/to/file.ext?q=1');

if ($uri->scheme_name == 'https') {
	echo 'Uses SSL'.PHP_EOL;
} else {
	echo 'Does not use SSL'.PHP_EOL;
}

// Change to an absolute path
$abs_path = $_SERVER['DOCUMENT_ROOT'].$uri->path;
echo $abs_path.PHP_EOL;

// easier to read links
printf('%2$s', $uri->str(), $uri->host.$uri->path);

// FTP logins
$uri = new uri('ftp://jdoe@example.com/my/home/dir');
$login = array(
	'username' => $uri->user,
	'password' => $user_input,
	'domain'   => $uri->host,
	'path'     => $uri->path
);
```

**Output:**

```
Does not use SSL
/var/www/path/to/file.ext
example.com/path/to/file.ext
```

#### Example #4: Works With A Wide Range Of URIs

[](#example-4-works-with-a-wide-range-of-uris)

Works perfectly with email, skype, and ssh URIs. The parser is based directly off the URI standard, so it will work well with uncommon and new URI types.

```
$uri1 = new uri('git@github.com:ProjectCleverWeb/PHP-URI.git');
$uri2 = new uri('example@gmail.com');

// Publish you source to multiple services?
echo $uri1.PHP_EOL; // PHP will automatically get the current URI
echo $uri1->replace('HOST', 'gitlab.com').PHP_EOL;
echo $uri1->replace('HOST', 'bitbucket.org').PHP_EOL.PHP_EOL;

// Quick and easy email template URI
$uri2->chain()
	->replace('SCHEME', 'mailto:')
	->query_replace('subject', 'Re: [Suggestion Box]')
	->query_replace('body', 'More snickers in the break room please!')
;
printf('%2$s', $uri2, $uri2->authority);
```

**Output:**

```
git@github.com:ProjectCleverWeb/PHP-URI.git
git@gitlab.com:ProjectCleverWeb/PHP-URI.git
git@bitbucket.org:ProjectCleverWeb/PHP-URI.git

example@gmail.com
```

Known Issues
------------

[](#known-issues)

- Cloning doesn't work as expected (use `$clone = new \uri($original->str()); $clone->input = $original->input;` instead)
- You cannot directly change the authority of a URI. This is intentional, as the authority is generated from the current URI.

License
-------

[](#license)

> The MIT License (MIT)
>
> Copyright (c) 2014 Nicholas Jordon - All Rights Reserved
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

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

Total

2

Last Release

4303d ago

PHP version history (2 changes)1.0.0-RC2PHP &gt;=5.3.7

1.0.0PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/974e725859b1a78b5d234748e489409f1654caa31a1f0e9e8aa32a9a212c7f06?d=identicon)[ProjectCleverWeb](/maintainers/ProjectCleverWeb)

---

Top Contributors

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

---

Tags

urluriparse\_urlwebaddress

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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)[opis/uri

Build, parse and validate URIs and URI-templates

1620.8M6](/packages/opis-uri)[cybercog/laravel-optimus

An Optimus bridge for Laravel. Id obfuscation based on Knuth's multiplicative hashing method.

192564.1k](/packages/cybercog-laravel-optimus)[ml/iri

IRI handling for PHP

276.4M6](/packages/ml-iri)[rowbot/url

A WHATWG URL spec compliant URL parser for working with URLs and their query strings.

19648.2k4](/packages/rowbot-url)

PHPackages © 2026

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