PHPackages                             malenki/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. [HTTP &amp; Networking](/categories/http)
4. /
5. malenki/url

ActiveLibrary[HTTP &amp; Networking](/categories/http)

malenki/url
===========

Simple class to deal with URL, using magic getter, multisyntaxic way, to play with URL like yoou want!

0.1.0(12y ago)16[1 issues](https://github.com/malenkiki/url/issues)MITPHPPHP &gt;=5.3.0

Since Apr 17Pushed 11y ago2 watchersCompare

[ Source](https://github.com/malenkiki/url)[ Packagist](https://packagist.org/packages/malenki/url)[ Docs](https://github.com/malenkiki/url)[ RSS](/packages/malenki-url/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Url
===

[](#url)

[![Build Status](https://camo.githubusercontent.com/d26449139691eb76c31412025bfd5418818c1327cccf91dec597ca4563565b56/68747470733a2f2f7472617669732d63692e6f72672f6d616c656e6b696b692f75726c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/malenkiki/url)

Handle URL with ease!

Introduction
------------

[](#introduction)

To play with URL string in PHP, you have to deal with some functions, not easy at all. With my little lib, you can get/set/icomplete/avoid many part of an URL. So, quick example to give you some idea:

```
$u = new Url('http://username:password@hostname:8080/path?arg=value#anchor');
echo $u->credential;
echo $u->host;

// you can change some parts using this way:
$u->credential->user = 'login';
$u->host = 'example.org'
$u->query->foo = 'bar';

// you can use other way too:
$u->user('login')->host('example.org')->query(array('foo', 'bar'));

// toString available:
echo $u; // http://login:password@example.org:8080/path?arg=value&foo=bar#anchor
```

How to use it
-------------

[](#how-to-use-it)

You can handle URL using two ways:

- chainable methods of Url class
- call some methods on URL's parts to have finest control.

### Only URL class

[](#only-url-class)

#### Set values or complete thems

[](#set-values-or-complete-thems)

Each URL part can be called with its name as a chainable method, as you can see into the following example:

```
$u = new Url('http://username:password@hostname:8080/path?arg=value#anchor');
$u->user('login')->host('example.org')->query(array('foo', 'bar'));
```

You must notice that methods `path()` and `query()` do not remove original content, but complete it with value given as argument. You must disable respective part before, like explained into next part.

#### Disable parts or test their availability

[](#disable-parts-or-test-their-availability)

Some more actions are available too, by using methods `no()`, `disable()` and `has()`:

- `no()` and `disable()` are both the same effect, one is alias of other, and take one argument, a string or an array of string. Argument must contain an URL part (`scheme`, `port`…). So, `$u->no('port')` disables port part and `$u->disable(array('query', 'path'))` removes query and path parts from the URL.
- `has()` tests whether a part is available into the URL or not. Simple, you give the name of the part to test and the method return `true` if it finds the part filled.

All methods explained into this section can be called using magic getter by using method name as prefix, followed by underscore and the part's name, so, you can do this for example:

```
echo $u->no_port->disable_credential;
var_dump($u->has_port);
```

### Act on URL's parts

[](#act-on-urls-parts)

You have finest control using method relative to URL parts:

```
$u = new Url('http://username:password@hostname:8080/path?arg=value#anchor');
$u->anchor->clear; // delete anchor
$u->path->add('other'); // add branch to path
$u->query->arg = 'other_value'; // Changed one arg of the query string
```

#### Common methods

[](#common-methods)

Each part has at least this methods:

- `isVoid()` to test whether the part has content or not
- `clear()` to avoid the part
- `toString()` is available

#### Set in one shot

[](#set-in-one-shot)

You can set part directly (override original content):

```
$u = new Url('http://username:password@hostname:8080/path?arg=value#anchor');
$u->path = 'other/path'; //or using array
$u->anchor = 'new_anchor';
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

4411d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6af62130bd16d4e6bbaa5877829b6377386ef9fb6593592052dbb6eeb87c4a02?d=identicon)[malenki](/maintainers/malenki)

---

Top Contributors

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

---

Tags

httpurlstringqueryhostfragmentschemeanchorcredential

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.2k](/packages/guzzlehttp-psr7)[league/uri-components

URI components manipulation library

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

URI manipulation library

1.1k206.4M277](/packages/league-uri)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

538204.9M23](/packages/league-uri-interfaces)[jbzoo/utils

Collection of PHP functions, mini classes and snippets for everyday developer's routine life.

8321.5M36](/packages/jbzoo-utils)[nette/http

🌐 Nette Http: abstraction for HTTP request, response and session. Provides careful data sanitization and utility for URL and cookies manipulation.

48619.2M541](/packages/nette-http)

PHPackages © 2026

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