PHPackages                             mschreiber/earl - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. mschreiber/earl

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

mschreiber/earl
===============

Earl is a single class library for parsing, building, modifying, and printing URL strings.

v0.1(5y ago)07MITPHP

Since Feb 16Pushed 5y ago1 watchersCompare

[ Source](https://github.com/mschreiber68/Earl)[ Packagist](https://packagist.org/packages/mschreiber/earl)[ RSS](/packages/mschreiber-earl/feed)WikiDiscussions master Synced 6d ago

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

Earl
====

[](#earl)

Earl is a single class library for parsing, building, modifying, and printing URL strings.

Inspired by libraries like jQuery and [Requests](https://requests.readthedocs.io/en/master/) for Python, it aims to make working with URLs as convenient as possible.

Usage
=====

[](#usage)

```
use Earl\Url;

```

#### Creating:

[](#creating)

```
// From a string
$url1 = Url::from('https://website.com/my/path?key=value');

// From another Earl\Url
$url2 = Url::from($url1);

// From an array
$url3 = Url::from([
    'host' => 'website.com',
    'path' => '/my/path',
    'query' => ['key' => 'value']  // can also use 'q'
]);

// cloneable
$url4 = clone $url3;

// Create empty url
$url5 = new Url();

```

#### Printing:

[](#printing)

```
$urlString = (string) $url;
$urlString = $url->str();

```

#### Modifying:

[](#modifying)

```
$url = new Url();

// Argument sets value
$url->host('website.com');

// No arguments gets value
$host = $url->host();

// Fluent setters
$url->path('my/path')
    ->path($url->path() . '/morepath');

assert($url == 'https://website.com/my/path/morepath');

```

### Working with query data

[](#working-with-query-data)

```
// Get param value
$url->q('a');

// Get entire query
$url->q();

// Set query param
$url->q('a', 1);

// Set entire query
$url->q(['a' => 1, 'b' => 2])

// Null values will not appear in URL string
$url->q('a', null);

```

Query encoding and decoding has the same behavior as [parse\_url](https://www.php.net/manual/en/function.parse-url) and [http\_build\_query](https://www.php.net/manual/en/function.http-build-query.php)

```
$url = Url::from('http://website.com?a=%28myparam%29%21+is+encoded');
assert($url->q('a') == '(myparam)! is encoded');

$url = Url::from('http://website.com')->q('a', '(myparam)! is encoded');
assert($url == 'http://website.com?a=%28myparam%29%21+is+encoded');

```

### Partial URLs

[](#partial-urls)

If the host is omitted, the URL will be a "partial" URL consisting of only the path, query, and fragment.

```
$url = Url::from([
    'path' => '/my/path',
    'q' => ['a' => 1],
    'fragment' => 'frag
]);

assert($url == '/my/path?a=1#frag');

```

### Auth

[](#auth)

```
$url = Url::from('http://website.com')
    ->user('me@email.com')
    ->pass('secret');

assert($url == 'http://me%40email.com:secret@website.com');

```

### Global defaults

[](#global-defaults)

You may be working in a context where most of the URLs you build will have the same scheme, host, etc. You can set global defaults for these values:

```
Url::defaults(['scheme' => 'https', 'host' => 'www.mywebsite.com']);

$url = Url::from('/my/path?a=1');
assert($url == 'https://www.mywebsite.com/my/path?a=1');

// Clear defaults
Url::defaults();

```

The default scheme is `https`

Currently only `scheme` and `host` are supported as defaults.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

1916d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3517763c99185b7cda9391c99446766723ca414c0bd93290c3be7d25adce0485?d=identicon)[mschreiber68](/maintainers/mschreiber68)

---

Top Contributors

[![mschreiber68](https://avatars.githubusercontent.com/u/3856121?v=4)](https://github.com/mschreiber68 "mschreiber68 (12 commits)")

---

Tags

url

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mschreiber-earl/health.svg)

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

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[mck89/peast

Peast is PHP library that generates AST for JavaScript code

18834.7M29](/packages/mck89-peast)[vstelmakh/url-highlight

Library to parse urls from string input

102849.1k9](/packages/vstelmakh-url-highlight)[package-url/packageurl-php

Builder and parser based on the package URL (purl) specification.

131.8M3](/packages/package-url-packageurl-php)[ergebnis/json

Provides a Json value object for representing a valid JSON string.

2421.7M8](/packages/ergebnis-json)[ergebnis/json-pointer

Provides an abstraction of a JSON pointer.

1921.8M6](/packages/ergebnis-json-pointer)

PHPackages © 2026

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