PHPackages                             michaelhoughton/purl - 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. michaelhoughton/purl

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

michaelhoughton/purl
====================

URL Manipulation for PHP 8.1

1.0.0(2y ago)0205MITPHPPHP &gt;=8.1

Since Jul 28Pushed 2y agoCompare

[ Source](https://github.com/MichaelHoughton/purl)[ Packagist](https://packagist.org/packages/michaelhoughton/purl)[ Docs](http://github.com/jwage/purl)[ RSS](/packages/michaelhoughton-purl/feed)WikiDiscussions master Synced 1mo ago

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

Purl
====

[](#purl)

Purl is a simple Object Oriented URL manipulation library for PHP 8.1. This is a fork of ecomailcz/purl which doesn't work for PHP 8.1 - this package solves that.

[![Build Status](https://camo.githubusercontent.com/8ebe2b2245ca3630f0350fa32fe071b2901cd15d2c4e443570f90bf9418fb7d7/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6a776167652f7075726c2e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/jwage/purl)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/0238d58527f25483dd1517aea4ee6d9331dc4a54c6e061f3da94f7519de01b9b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a776167652f7075726c2f6261646765732f7175616c6974792d73636f72652e706e673f733d37653065316434623564376636626536316133636438303464626135353661306534643131343164)](https://scrutinizer-ci.com/g/jwage/purl/)[![Code Coverage](https://camo.githubusercontent.com/a582a02954c0e52c3e51bc50d53d0bd34794435c9d0f2b8fd5949f3c53b687f5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a776167652f7075726c2f6261646765732f636f7665726167652e706e673f733d61303233333262633464366133326466333137316632626137313465343538336137306330313534)](https://scrutinizer-ci.com/g/jwage/purl/)[![Latest Stable Version](https://camo.githubusercontent.com/6866ceb85603562994aab38c7a989a0699852cbe52f9e15bce7a6a00ee188727/68747470733a2f2f706f7365722e707567782e6f72672f6a776167652f7075726c2f762f737461626c652e706e67)](https://packagist.org/packages/jwage/purl)[![Total Downloads](https://camo.githubusercontent.com/5ead75613460958a6e3d25154292f754516dda6de6b384bd4dfecbf7e7fbc4b4/68747470733a2f2f706f7365722e707567782e6f72672f6a776167652f7075726c2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/jwage/purl)

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

[](#installation)

The suggested installation method is via [composer](https://getcomposer.org/):

```
composer require michaelhoughton/purl
```

Using Purl
----------

[](#using-purl)

Creating Url instances is easy. You can specify the URL you want, or just use the current URL:

```
use Purl\Url;

$url = new Url('http://jwage.com');
$currentUrl = Url::fromCurrent();
```

You can chain methods together after creating the `Url` like this:

```
$url = (new Url('http://jwage.com'))
    ->set('scheme', 'https')
    ->set('port', '443')
    ->set('user', 'jwage')
    ->set('pass', 'password')
    ->set('path', 'about/me')
    ->set('query', 'param1=value1&param2=value2')
    ->set('fragment', 'about/me?param1=value1&param2=value2');

echo $url->getUrl(); // https://jwage:password@jwage.com:443/about/me?param1=value1&param2=value2#about/me?param1=value1&param2=value2

// $url->path becomes instanceof Purl\Path
// $url->query becomes instanceof Purl\Query
// $url->fragment becomes instanceof Purl\Fragment
```

### Path Manipulation

[](#path-manipulation)

```
$url = new Url('http://jwage.com');

// add path segments one at a time
$url->path->add('about')->add('me');

// set the path data from a string
$url->path = 'about/me/another_segment'; // $url->path becomes instanceof Purl\Path

// get the path segments
print_r($url->path->getData()); // array('about', 'me', 'another_segment')
```

### Query Manipulation

[](#query-manipulation)

```
$url = new Url('http://jwage.com');
$url->query->set('param1', 'value1');
$url->query->set('param2', 'value2');

echo $url->query; // param1=value1&param2=value2
echo $url; // http://jwage.com?param1=value1&param2=value2

// set the query data from an array
$url->query->setData([
    'param1' => 'value1',
    'param2' => 'value2'
]);

// set the query data from a string
$url->query = 'param1=value1&param2=value2'; // $url->query becomes instanceof Purl\Query
print_r($url->query->getData()); //array('param1' => 'value1', 'param2' => 'value2')
```

### Fragment Manipulation

[](#fragment-manipulation)

```
$url = new Url('http://jwage.com');
$url->fragment = 'about/me?param1=value1&param2=value2'; // $url->fragment becomes instanceof Purl\Fragment
```

A Fragment is made of a path and a query and comes after the hashmark (#).

```
echo $url->fragment->path; // about/me
echo $url->fragment->query; // param1=value1&param2=value2
echo $url; // http://jwage.com#about/me?param1=value1&param2=value2
```

### Extract URLs

[](#extract-urls)

You can easily extract urls from a string of text using the `extract` method:

```
$string = 'some text http://google.com http://jwage.com';
$urls = Url::extract($string);

echo $urls[0]; // http://google.com/
echo $urls[1]; // http://jwage.com/
```

### Join URLs

[](#join-urls)

You can easily join two URLs together using Purl:

```
$url = new Url('http://jwage.com/about?param=value#fragment');
$url->join('http://about.me/jwage');

echo $url; // http://about.me/jwage?param=value#fragment
```

Or if you have another `Url` object already:

```
$url1 = new Url('http://jwage.com/about?param=value#fragment');
$url2 = new Url('http://about.me/jwage');
$url1->join($url2);

echo $url1; // http://about.me/jwage?param=value#fragment
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 61.1% 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

1021d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/36ff0f925b41887978347c0ed99ee187131f647b9f50bffe91b4465b6e6d7b86?d=identicon)[MichaelHoughton](/maintainers/MichaelHoughton)

---

Top Contributors

[![jwage](https://avatars.githubusercontent.com/u/97422?v=4)](https://github.com/jwage "jwage (88 commits)")[![jeremykendall](https://avatars.githubusercontent.com/u/288613?v=4)](https://github.com/jeremykendall "jeremykendall (22 commits)")[![dpi](https://avatars.githubusercontent.com/u/21850?v=4)](https://github.com/dpi "dpi (3 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (3 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (3 commits)")[![acidvertigo](https://avatars.githubusercontent.com/u/809397?v=4)](https://github.com/acidvertigo "acidvertigo (2 commits)")[![MichaelHoughton](https://avatars.githubusercontent.com/u/5341149?v=4)](https://github.com/MichaelHoughton "MichaelHoughton (2 commits)")[![paulredmond](https://avatars.githubusercontent.com/u/177773?v=4)](https://github.com/paulredmond "paulredmond (2 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (2 commits)")[![Tlapi](https://avatars.githubusercontent.com/u/2815391?v=4)](https://github.com/Tlapi "Tlapi (2 commits)")[![b-alidra](https://avatars.githubusercontent.com/u/372249?v=4)](https://github.com/b-alidra "b-alidra (1 commits)")[![atijust](https://avatars.githubusercontent.com/u/1526990?v=4)](https://github.com/atijust "atijust (1 commits)")[![kbond](https://avatars.githubusercontent.com/u/127811?v=4)](https://github.com/kbond "kbond (1 commits)")[![longchiwen](https://avatars.githubusercontent.com/u/1258717?v=4)](https://github.com/longchiwen "longchiwen (1 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (1 commits)")[![mmcev106](https://avatars.githubusercontent.com/u/2627854?v=4)](https://github.com/mmcev106 "mmcev106 (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![Seldaek](https://avatars.githubusercontent.com/u/183678?v=4)](https://github.com/Seldaek "Seldaek (1 commits)")[![arnaud-lb](https://avatars.githubusercontent.com/u/365207?v=4)](https://github.com/arnaud-lb "arnaud-lb (1 commits)")

---

Tags

urlmanipulation

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/michaelhoughton-purl/health.svg)

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

###  Alternatives

[doctrine/inflector

PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.

11.4k855.8M711](/packages/doctrine-inflector)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[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)

PHPackages © 2026

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