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

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

mtchabok/url
============

PHP Url Class

v1.2(4y ago)121MITPHPPHP &gt;=7.2

Since May 13Pushed 4y agoCompare

[ Source](https://github.com/mtchabok/url)[ Packagist](https://packagist.org/packages/mtchabok/url)[ RSS](/packages/mtchabok-url/feed)WikiDiscussions v1.2 Synced 2d ago

READMEChangelog (6)DependenciesVersions (11)Used By (0)

PHP Url
=======

[](#php-url)

PHP class for handling URLs.

- Parse Url string Customized and create objects
- check relative url
- add or modify any part of the url objects
- add or modify query parameters
- compare any part of url with another url or part of that
- support PSR-7 method`s

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

[](#installation)

This package is listed on [Packagist](https://packagist.org/packages/mtchabok/url).

```
composer require mtchabok/url

```

How To Usage
------------

[](#how-to-usage)

#### Create Url Object

[](#create-url-object)

```
use \Mtchabok\Url\Url;

$url = new Url('https://www.domain.com/dir1/dir2/file.ext?param1=val1&param2=val2');

$url = Url::newUrl('https://www.domain.com/dir1/dir2/file.ext?param1=val1&param2=val2');

$url = Url::newUrl()
	->setScheme('https')
	->setAuthority('www.domain.com')
	->setPath('/dir1/dir2/file.ext')
	->setQuery('param1=val1&param2=val2')
;
```

#### Modify Url Object

[](#modify-url-object)

```
use \Mtchabok\Url\Url;
$url = Url::newUrl();
// change scheme
$url->setScheme('http'); // return $url object
$url->scheme = 'http';

// change authority = user: sam, pass: 123, host: domain.com
$url->setAuthority('sam:123@domain.com'); // return $url object

// change url path.
$url->setPath('/dir2/dir1/'); // return $url object
$url->path = '/dir2/dir1/';

// add path
$url->addPath('./dir3/file.ext2'); // return $url object
$url->path = $url::normalizePath($url->path, './dir3/file.ext2');

// change query
$url->setQuery('p12=32&name=sara'); // return $url object
$url->query = 'p12=32&name=sara';

// set query param
$url->getQuery()->set('param1', 'test'); // return Url Query object
$url->query->set('param1', 'test'); // return Url Query object
$url->getQuery()->set('param4', ['p4_1'=>'val41', 'p4_2'=>'val42']); // return Url Query object
$url->query['param4'] = ['p4_1'=>'val41', 'p4_2'=>'val42']; // return Url Query object

// change fragment
$url->setFragment('index12'); // return $url object
$url->fragment = 'index12';
```

#### Check exist or set Url Properties

[](#check-exist-or-set-url-properties)

```
use \Mtchabok\Url\Url;
$url = Url::newUrl();
// check scheme set
$url->hasScheme(); // return bool

// check userInfo set
$url->hasUserInfo(); // return bool
$url->hasUser(); // return bool
$url->hasPass(); // return bool

// check host set
$url->hasHost(); // return bool

// check port set
$url->hasPort(); // return bool

// check path set
$url->hasPath(); // return bool

// check query set
$url->hasQuery(); // return bool

// and ...
```

#### Get Url Properties

[](#get-url-properties)

```
use \Mtchabok\Url\Url;
$url = Url::newUrl();
// scheme
$url->getScheme(); // return current scheme or empty string
$url->scheme; // return current scheme or null
$url->getScheme('file'); // reutrn current scheme or 'file'

// user info
$url->getUserInfo(); // return current userinfo or empty string
$url->getUserInfo('test:123'); // return current userinfo or 'test:123'

// host
$url->getHost();  // return current host or empty string
$url->getHost('host.org');  // return current host or 'host.org'

// path
$url->getPath();  // return current path or empty string
$url->getPath('/dir1/dir2/file');  // return current path or '/dir1/dir2/file'
```

#### PSR-7 and Equals Method`s

[](#psr-7-and-equals-methods)

```
use \Mtchabok\Url\Url;
$url = Url::newUrl('https://www.domain.com/dir1/dir2/file.ext');

$url2 = $url->withHost('site.com'); // return new Url Object with host 'site.com'

$url->equalsHost($url2->getHost()); // return false
$url->equalsHost($url2); // return false
```

#### For More Usage Documentation, Use This Url Class By IDE

[](#for-more-usage-documentation-use-this-url-class-by-ide)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity61

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

Recently: every ~134 days

Total

11

Last Release

1643d ago

Major Versions

v0.1.2.x-dev → v1.02020-05-25

PHP version history (2 changes)0.1.0PHP &gt;=7.0

v1.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ffa7dd709b65d7cb654af598deedb150bbf8075c70a6bdce2ddc4e3d278c644?d=identicon)[mtchabok](/maintainers/mtchabok)

---

Top Contributors

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

---

Tags

phpphp7urlurl-parsingurlliburlphp urlurl-class

### Embed Badge

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

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

###  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)
