PHPackages                             bentools/hostname-extractor - 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. bentools/hostname-extractor

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

bentools/hostname-extractor
===========================

Hostname extractor - A library to find parts of a hostname (suffix, tld, subdomain, ...)

1.3(7y ago)05741MITPHPPHP &gt;=7.1

Since Dec 8Pushed 7y ago1 watchersCompare

[ Source](https://github.com/bpolaszek/hostname-extractor)[ Packagist](https://packagist.org/packages/bentools/hostname-extractor)[ RSS](/packages/bentools-hostname-extractor/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (11)Versions (8)Used By (1)

[![Latest Stable Version](https://camo.githubusercontent.com/21a5af900b5286755aeb5d8c4d7bd68adbf16c44557024feff9c9fea9814ae26/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f686f73746e616d652d657874726163746f722f762f737461626c65)](https://packagist.org/packages/bentools/hostname-extractor)[![License](https://camo.githubusercontent.com/36c0dbdb06f22ee39b8fc3443819e767191b5b2fa7f833bac1fb5ad63c3ce318/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f686f73746e616d652d657874726163746f722f6c6963656e7365)](https://packagist.org/packages/bentools/hostname-extractor)[![Build Status](https://camo.githubusercontent.com/30ef7fe0d225500c2f28ffc168d18dcfc2f80fa08793cbcf5d3508d94e8cea41/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62706f6c61737a656b2f686f73746e616d652d657874726163746f722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/bpolaszek/hostname-extractor)[![Coverage Status](https://camo.githubusercontent.com/2b2f75e27dfdc222a98cf095d631e48292a36b9ca96fb00c9604cbad54eb8f21/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f62706f6c61737a656b2f686f73746e616d652d657874726163746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/bpolaszek/hostname-extractor?branch=master)[![Quality Score](https://camo.githubusercontent.com/8ba2c9d1a4edbe466b773d467e320c1614469cdca45c8e1d14218c36dc693ba4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62706f6c61737a656b2f686f73746e616d652d657874726163746f722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bpolaszek/hostname-extractor)[![Total Downloads](https://camo.githubusercontent.com/8eb8c91343173c274530267d7ea978f19433e72cd6c72dcfeca154b0681f08d9/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f686f73746e616d652d657874726163746f722f646f776e6c6f616473)](https://packagist.org/packages/bentools/hostname-extractor)

Hostname Extractor
==================

[](#hostname-extractor)

A simple library to manipulate domains.

Usage
-----

[](#usage)

```
require_once __DIR__ . '/vendor/autoload.php';

use BenTools\HostnameExtractor\HostnameExtractor;
use BenTools\HostnameExtractor\SuffixProvider\PublicSuffixProvider;

$extractor = new HostnameExtractor(new PublicSuffixProvider());
$hostname = $extractor->extract('my.preferred.domain.co.uk');
dump($hostname->getSubdomain()); // my.preferred
dump($hostname->getDomain()); // domain
dump($hostname->getSuffix()); // co.uk
dump($hostname->getTld()); // uk
dump($hostname->getSuffixedDomain()); // domain.co.uk
dump($hostname->isIp()); // false
dump($hostname->isIpv4()); // false
dump($hostname->isIpv6()); // false
```

As you can see, `co.uk` is considered as a suffix (otherwise, we would have considered that `co` is the domain and `uk` the suffix / tld).

The library parses the [Public Suffix List](https://publicsuffix.org/), which stores thousands of existing suffixes.

To avoid network latency feel free to implement your own `BenTools\HostnameExtractor\SuffixProvider\SuffixProviderInterface` or to use your favorite [PSR-16](http://www.php-fig.org/psr/psr-16/) library into a `BenTools\HostnameExtractor\SuffixProvider\PSR16CacheSuffixProvider` object.

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

[](#installation)

PHP 7.1+ with `mbstring` extension is required.

> composer require bentools/hostname-extractor ^1.0

Tests
-----

[](#tests)

> ./vendor/bin/phpunit

License
-------

[](#license)

MIT.

See also
--------

[](#see-also)

[bentools/querystring](https://github.com/bpolaszek/querystring) - Easily manipulate your query strings.

[bentools/uri-factory](https://github.com/bpolaszek/uri-factory) - PSR-7 `UriInterface` factory with multiple libaries support.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

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

Recently: every ~122 days

Total

7

Last Release

2578d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/acdd1a8ee0e657ddd06cf11f98a32100ef7121afb8aa270a5b295f5c29c038b3?d=identicon)[bpolaszek](/maintainers/bpolaszek)

---

Top Contributors

[![bpolaszek](https://avatars.githubusercontent.com/u/5569077?v=4)](https://github.com/bpolaszek "bpolaszek (10 commits)")

---

Tags

domainhosthostnamephpuriurlurlurihostnamehostsubdomaindomainextractortldsuffix

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/bentools-hostname-extractor/health.svg)

```
[![Health](https://phpackages.com/badges/bentools-hostname-extractor/health.svg)](https://phpackages.com/packages/bentools-hostname-extractor)
```

###  Alternatives

[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)[cybercog/laravel-optimus

An Optimus bridge for Laravel. Id obfuscation based on Knuth's multiplicative hashing method.

192564.1k](/packages/cybercog-laravel-optimus)[opis/uri

Build, parse and validate URIs and URI-templates

1620.8M6](/packages/opis-uri)[ml/iri

IRI handling for PHP

276.4M6](/packages/ml-iri)[rowbot/url

A WHATWG URL spec compliant URL parser for working with URLs and their query strings.

19648.2k4](/packages/rowbot-url)

PHPackages © 2026

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