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

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

weew/url
========

Simple url wrapper.

v2.2.0(9y ago)0528[1 issues](https://github.com/weew/url/issues)3MITPHP

Since Jul 21Pushed 9y ago1 watchersCompare

[ Source](https://github.com/weew/url)[ Packagist](https://packagist.org/packages/weew/url)[ RSS](/packages/weew-url/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (7)Versions (22)Used By (3)

URL wrapper
===========

[](#url-wrapper)

[![Build Status](https://camo.githubusercontent.com/0e95ae8957a2b819cca151aa7a0158aa5a90bef82c8ce959ac97fd9d02d3643d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f776565772f75726c2e737667)](https://travis-ci.org/weew/url)[![Code Quality](https://camo.githubusercontent.com/d365f09c79d1af19ddc81c73f573a110567c09e65cd6aca861b09c9b7f7f1e8f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776565772f75726c2e737667)](https://scrutinizer-ci.com/g/weew/url)[![Test Coverage](https://camo.githubusercontent.com/5b062e952e091d85be7b9c808e45961862074379c846830a1781e7ef06399eec/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f776565772f75726c2e737667)](https://coveralls.io/github/weew/url)[![Dependencies](https://camo.githubusercontent.com/c8c8bf0fdf730ea4e1c2029d9a89024e2d4e1ad7cfdc91af9244ace9ffb98f76/68747470733a2f2f696d672e736869656c64732e696f2f76657273696f6e6579652f642f7068702f776565773a75726c2e737667)](https://versioneye.com/php/weew:url)[![Version](https://camo.githubusercontent.com/2d4bc6307883d2eb6db872ec3850f5b30c37c57796b4a5389bf9fa6ee79fffe2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776565772f75726c2e737667)](https://packagist.org/packages/weew/url)[![Licence](https://camo.githubusercontent.com/8c3d11a1892498ef8d8cb8def30713ec8716a0b7db3e2383876ecb71466e805e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776565772f75726c2e737667)](https://packagist.org/packages/weew/url)

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Overview](#overview)
- [Instantiation](#instantiation)
- [Parsing](#parsing)
- [Building](#building)
- [Matching](#matching)
- [Parsing](#parsing)
- [Replacing](#building)

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

[](#installation)

`composer require weew/url`

Overview
--------

[](#overview)

Currently this library is able to parse and build urls of such format and complexity:

```
// protocol://username:password@subdomain.domain.tld:port/path?key=value#fragment
```

For example:

```
// https://john:doe@another.domain.net:8080/my/path?query=value&some=value#hashtag
```

Instantiation
-------------

[](#instantiation)

Creating a new url is very easy:

```
$url = new Url('http://username:password@subdomain.domain.com:80/some/path?query=value#fragment');
```

Parsing
-------

[](#parsing)

Url containts manny segments which can be accessed trough convenient methods:

```
echo $url->getProtocol();
// http

echo $url->getHost();
// subdomain.domain.com

echo $url->getDomain();
// domain

echo $url->getSubdomain();
// subdomain

echo $url->getTLD();
// com

echo $url->getPort();
// 80

echo $url->getPath();
// /some/path

echo $url->getQuery();
// query=value

echo $url->getFragment();
// fragment

echo $url->getUsername();
// username

echo $url->getPassword();
// password
```

Building
--------

[](#building)

You can modify url segments in the same manner.

```
$url->setProtocol('https');

$url->setHost('another.domain.net');
// or
$url->setDomain('domain');
$url->setSubdomain('another');
$url->setTLD('net');

$url->setPort(8080);
$url->setPath('my/path');
$url->addPath('here');
$url->getQuery()->set('some', 'value');
$url->setFragment('hashtag');
$url->setUsername('john');
$url->setPassword('doe');

echo $url;
// https://john:doe@another.domain.net:8080/my/path/here?query=value&some=value#hashtag
```

Matching
--------

[](#matching)

You can match url path against a pattern.

```
$url = new Url('users/1');
// true
$url->match('users/{id}');

$url = new Url('users');
// false
$url->match('users/{id}');
```

Placeholders can be optional by adding the `?` sign at the end.

```
$url = new Url('users/1');
// true
$url->match('users/{id?}');

$url = new Url('users');
// true
$url->match('users/{id?}');
```

Placeholders can have custom patterns.

```
$url = new Url('users/1');
// true
$url->match('users/{id}', [
    'id' => '[0-9]+',
]);

$url = new Url('users/abc');
// false
$url->match('users/{id}', [
    'id' => '[0-9]+',
]);
```

For further documentation check out the [weew/url-matcher](https://github.com/weew/url-matcher) package;

Parsing
-------

[](#parsing-1)

Retrieving placeholder values is very trivial.

```
$url = new Url('users/1');
$dictionary = $url->parse('users/{id}');
// 1
$dictionary->get('id');
```

For further documentation check out the [weew/url-matcher](https://github.com/weew/url-matcher) package;

Replacing
---------

[](#replacing)

You can replace placeholders inside your path with values.

```
$url = new Url('{subdomain}.service.com/users/{id}/profile');
$url->replace('subdomain', 'api');
$url->replace('id', 1);

// or
$url->replaceAll(['subdomain' => 'api', 'id' => 1]);

// api.service.com/users/1/profile
$url->toString();
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity72

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

Recently: every ~68 days

Total

21

Last Release

3416d ago

Major Versions

v0.1.2 → v1.0.02015-11-16

v1.5.2 → v2.0.02016-07-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/10b2b854b5829dd13a15967c000ed2119b5faef67aca24d94c653c8ac550d85e?d=identicon)[weew](/maintainers/weew)

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15312.0M36](/packages/magento-magento2-functional-testing-framework)[overtrue/chinese-calendar

中国农历转换与查询工具

558115.2k5](/packages/overtrue-chinese-calendar)[sitegeist/silhouettes

Preconfigure property-silhuettes that can be applied to various properties of multiple NodeTypes.

16160.5k](/packages/sitegeist-silhouettes)

PHPackages © 2026

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