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

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

osw3/uri
========

Parse and manipulate URI, URL and URN.

03PHP

Since Sep 9Pushed 6y agoCompare

[ Source](https://github.com/OSW3/uri)[ Packagist](https://packagist.org/packages/osw3/uri)[ RSS](/packages/osw3-uri/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

URI
===

[](#uri)

Parse and manipulate URI, URL and URN.

Install
-------

[](#install)

```
composer require osw3/uri
```

Usage
-----

[](#usage)

```
new Uri(string $uri);
```

- `$uri` (string) The URI you want to parse.

Parse URI
---------

[](#parse-uri)

```
// use namsespace
use OSW3\Uri;

// ...

// Instanciate Uri()
$uri = new Uri("http://foo.bar/opensource/database?param=value#resource");

// ..

// Get URI parameters
print_r( $uri->parameters() );
```

Output methods
--------------

[](#output-methods)

- `print([$type])`
    Return the string of URI

```
$uri->print();
$uri->print('uri'); // default
$uri->print('url');
$uri->print('urn');
```

- `parameters()`
    Return an array of all URI paramaters

```
$uri->parameters();
```

```
Array
(
    [original] => http://foo.bar/opensource/database?param=value#resource
    [hash] => 8055f2691c03d7ef54cbec8af205de5a
    [secured] =>
    [uri] => Array
        (
            [text] => http://foo.bar/opensource/database?param=value#resource=
            [md5] => 6c89b086480fbea32bacfd40251d7cce
            [sha1] => 901bfc28a6713be0de7c0948b031c6456bc05279
        )

    [url] => Array
        (
            [text] => http://foo.bar/opensource/database
            [md5] => 05386599aadf31b39042b64d77637a25
            [sha1] => 3f681fc482c68feb13f41654f354ec23a75844a4
        )

    [urn] => Array
        (
            [text] => foo.bar/opensource/database?param=value#resource=
            [md5] => e0c2f7057a96f7115844a3bc5eb62891
            [sha1] => 9e7d3b3bbc40810f62cbdb1e5ca9a7e8295a0215
        )

    [scheme] => http
    [protocol] => http://
    [user] =>
    [pass] =>
    [host] => foo.bar
    [registrable_domain] => foo.bar
    [subdomain] =>
    [hostname] => foo
    [tld] => bar
    [isValidDomain] => 1
    [isIp] =>
    [port] =>
    [path] => /opensource/database
    [segments] => Array
        (
            [0] => opensource
            [1] => database
        )

    [file] =>
    [dirname] =>
    [filename] =>
    [extension] =>
    [query] => param=value
    [parameters] => Array
        (
            [param] => value
        )

    [fragment] => resource
    [fragments] => Array
        (
            [resource] =>
        )

)
```

- `getUri()`

Return the original URI (your input)

```
$uri->getUri();
```

- `getScheme()` (string)

Return the URI Scheme. (e.g.: http, https)

```
$uri->getScheme();
```

- `getProtocol()` (string)

Return the URI Protocol. (e.g.: http://, https://)

```
$uri->getProtocol();
```

- `getIsSecured()` (bool)

Return TRUE if the transport is secured (e.g.: https).
Return FALSE if the transport is not secured (e.g.: http).

```
$uri->getIsSecured();
```

- `getUser()` (null|string)

Return the username of the URI

```
$uri->getUser();
```

- `getPass()` (null|string)

Return the password of the URI

```
$uri->getPass();
```

- `getHost()`

```
$uri->getHost();
```

- `getPort()`

```
$uri->getPort();
```

- `getPath()`

```
$uri->getPath();
```

- `getSegment()`

```
$uri->getSegment();
```

- `getSegments()`

```
$uri->getSegments();
```

- `getQuery()`

```
$uri->getQuery();
```

- `getParameter()`

```
$uri->getParameter();
```

- `getParameters()`

```
$uri->getParameters();
```

- `getFragment()`

```
$uri->getFragment();
```

- `getFragmentsParameter()`

```
$uri->getFragmentsParameter();
```

- `getFragments()`

```
$uri->getFragments();
```

- `getHostname()`

```
$uri->getHostname();
```

- `getSubdomain()`

```
$uri->getSubdomain();
```

- `getTld()`

```
$uri->getTld();
```

- `getRegistrableDomain()`

```
$uri->getRegistrableDomain();
```

- `getIsValidDomain()`

```
$uri->getIsValidDomain();
```

- `getIsIp()`

```
$uri->getIsIp();
```

Manipulation
------------

[](#manipulation)

- `changeScheme(string $scheme)`
    Change the scheme (e.g.: http to view-source).
    All valid schemes [here](https://fr.wikipedia.org/wiki/Sch%C3%A9ma_d%27URI#Sch%C3%A9mas_enregistr%C3%A9s_aupr%C3%A8s_de_l'IANA).

```
$uri->changeScheme('view-source');
```

- `secure(bool $secure)`
    If `$secure` is TRUE, Set ON secure transnport (e.g.: http to https)
    If `$secure` is FALSE, Set OFF secure transnport (e.g.: https to http)

```
$uri->secure(true);
```

- `toggleSecure()`
    Toggle secure transnport

```
$uri->toggleSecure();
```

- `addUser()`
    Add User name if is not defined

```
$uri->addUser('Bob');
```

- `changeUser()`
    Change or Add User name

```
$uri->changeUser('John');
```

- `addPass()`
    Add Password if is not defined

```
$uri->addPass('123456!');
```

- `changePass()`
    Change or Add Password

```
$uri->changePass('l2EAS6!');
```

- `changeHost()`
    Change Full Host

```
$uri->changeHost('www.google.com');
```

- `addSubdomain()`
    Add SubDomain if is not defined

```
$uri->addSubdomain('app');
```

- `changeSubdomain()`
    Change or Add SubDomain

```
$uri->changeSubdomain('store');
```

- `removeSubdomain()`
    Remove SubDomain

```
$uri->removeSubdomain();
```

- `changeHostname()`
    Change the Hostname

```
$uri->changeHostname('goo');
```

- `changeTld()`
    Change the TLD

```
$uri->changeTld('gl');
```

- `addPort()`
    Add Port if is not defined

```
$uri->addPort(8080);
```

- `changePort()`
    Change or Add Port

```
$uri->changePort(8082);
```

- `addSegment()`
    Add a segment

```
$uri->addSegment('folder_A');
```

- `replaceSegment()`
    Replace a segment

```
$uri->replaceSegment(1, 'folder_C'); // Replace the N segment
$uri->replaceSegment('folder_B', 'folder_C'); // Replace the segment 'folder_B'
```

- `removeSegment()`
    Remove a segment

```
$uri->removeSegment('folder_A');
```

- `removeSegments()`
    Remove all segments

```
$uri->removeSegments();
```

- `resetSegments()`
    Reset segments

```
$uri->resetSegments();
```

- `addParameter()`
    Add a parameter

```
$uri->addParameter('p1', 'lorem ipsum');
```

- `replaceParameter()`
    Replace a parameter

```
$uri->replaceParameter('p2', 42);
```

- `removeParameter()`
    Remove a parameter

```
$uri->removeParameter('p2');
```

- `removeParameters()`
    Remove all parameters

```
$uri->removeParameters();
```

- `resetParameters()`
    Reset parameters

```
$uri->resetParameters();
```

- `addFragment()`
    Add a fragment

```
$uri->addFragment('p1', 'lorem ipsum');
```

- `replaceFragment()`
    Replace a fragment

```
$uri->replaceFragment('p2', 42);
```

- `removeFragment()`
    Remove a fragment

```
$uri->removeFragment('p2');
```

- `removeFragments()`
    Remove all fragments

```
$uri->removeFragments();
```

- `resetFragments()`
    Reset fragments

```
$uri->resetFragments();
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3fb494ca5da6d3783e7ccfa656354d43d111a024b573051f5ca8f922b0d386ca?d=identicon)[osw3](/maintainers/osw3)

---

Top Contributors

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

### Embed Badge

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

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

PHPackages © 2026

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