PHPackages                             silvarcode/domain-parser - 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. silvarcode/domain-parser

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

silvarcode/domain-parser
========================

A high-performance PHP library for validating and parsing domain names using the Public Suffix List.

1.0.0(11mo ago)0208MITPHPPHP ^8.2

Since Jun 7Pushed 11mo agoCompare

[ Source](https://github.com/SilvarCode/Domain-Parser)[ Packagist](https://packagist.org/packages/silvarcode/domain-parser)[ Docs](https://github.com/silvarcode/domain-parser)[ RSS](/packages/silvarcode-domain-parser/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

SilvarCode Domain Parser
========================

[](#silvarcode-domain-parser)

![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)![Release](https://camo.githubusercontent.com/535b128265fdd897634387021b4fcd2f337f963bb90acc4f6a5a35fc35991fa8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656c656173652d6c61746573742d626c75652e737667)

**SilvarCode Domain Parser** is a robust and efficient PHP library for parsing and validating domain names using the [Public Suffix List](https://publicsuffix.org).

It supports complex TLD structures and wildcard suffixes, making it suitable for both general-purpose and enterprise-level domain validation.

Features
--------

[](#features)

- ✅ Parses **registrable domains** from full hostnames
- 🔍 Extracts **subdomain** and **subdomain hierarchy**
- 🌐 Supports wildcard and multi-level TLDs (e.g., `*.k12.ak.us`, `*.sch.uk`)
- 📥 Uses the official Public Suffix List
- 🧠 Configurable **in-memory caching**
- 🛠️ Custom suffix injection for **internal/private networks**

Requirements
------------

[](#requirements)

- PHP 8.2 or higher

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

[](#installation)

```
composer require silvarcode/domain-parser
```

Usage
-----

[](#usage)

### Instantiating the DomainParser

[](#instantiating-the-domainparser)

You can create a new instance of the `DomainParser` class with optional memory caching enabled and provide custom suffixes if needed:

ParameterTypeDescription`memoryCache`boolWhether to load the suffix set into memory for improved performance`suffixSet`arrayAn optional list of custom suffixes (e.g., for internal domains)### Example

[](#example)

```
use SilvarCode\DomainParser\Parser\DomainParser;

// Instantiate parser with memory cache enabled
$parser = new DomainParser(true);

// Instantiate parser with memory cache and custom suffixes
$parser2 = new DomainParser(true, ['com.internal']);

$checkHost1 = 'sub2.sub1.example.com';
$checkHost2 = 'sub2.sub1.example.com.internal';

// Show parsing results for checkHost1 using $parser
$parser->showResult([
    'tld' => $parser->tld($checkHost1),
    'domain' => $parser->getRegistrableDomain($checkHost1),
    'subdomain' => $parser->getSubdomain($checkHost1),
    'subdomains' => $parser->getSubdomains($checkHost1),
]);

// Show parsing results for checkHost2 using $parser
$parser->showResult([
    'tld' => $parser->tld($checkHost2),
    'domain' => $parser->getRegistrableDomain($checkHost2),
    'subdomain' => $parser->getSubdomain($checkHost2),
    'subdomains' => $parser->getSubdomains($checkHost2),
]);

// Show parsing results for checkHost2 using $parser2 with custom suffixes
$parser2->showResult([
    'tld' => $parser2->tld($checkHost2),
    'domain' => $parser2->getRegistrableDomain($checkHost2),
    'subdomain' => $parser2->getSubdomain($checkHost2),
    'subdomains' => $parser2->getSubdomains($checkHost2),
]);
```

### 💻 Command-Line Usage (via Composer)

[](#-command-line-usage-via-composer)

If you’ve defined the CLI entry point in composer.json like this:

```
"bin": [
  "bin/check.php"
],
"scripts": {
  "check-domain": "bin/check.php"
}
```

You can run domain checks directly from the terminal:

```
composer check-domain sub2.sub1.example.com
```

Output:

```
Host: sub2.sub1.example.com
Domain: example.com
Subdomain: sub2
Subdomains:
  - sub2
  - sub1
```

Learn More!
-----------

[](#learn-more)

We’ve published an in-depth blog post on our website that covers the design, features, and practical usage of the SilvarCode Domain Parser.
It’s a great resource if you want to understand the package better or see real-world examples.

👉 [Read the full blog post here](https://silvarcode.com/blog/en-gb/post/a062f6fa-f753-4c3c-8031-20a65b8e9aff/introducing-silvarcode-domain-parser-a-simple-and-accurate-php-tool-for-validation)

Feel free to share your feedback or questions in the GitHub issues or discussions!

License
-------

[](#license)

**MIT License**
© 2025 SILVARCODE LTD
Author: Marcus Ribeiro ()

This software is provided *"as is"*, without any warranty of any kind whatsoever.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance51

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

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

345d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

domaindomain-parserparserphpurlphpparsersubdomaindomaintldPublic Suffix ListPSLdomain parserdomain validator

### Embed Badge

![Health badge](/badges/silvarcode-domain-parser/health.svg)

```
[![Health](https://phpackages.com/badges/silvarcode-domain-parser/health.svg)](https://phpackages.com/packages/silvarcode-domain-parser)
```

###  Alternatives

[io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

4922.4M8](/packages/io-developer-php-whois)[simplehtmldom/simplehtmldom

A fast, simple and reliable HTML document parser for PHP.

1921.3M14](/packages/simplehtmldom-simplehtmldom)[corveda/php-sandbox

A PHP library that can be used to run PHP code in a sandboxed environment

23483.5k2](/packages/corveda-php-sandbox)[leonelquinteros/php-toml

PHP parser for TOML language ( https://github.com/toml-lang/toml )

266.7k](/packages/leonelquinteros-php-toml)

PHPackages © 2026

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