PHPackages                             jeremykendall/php-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jeremykendall/php-domain-parser

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

jeremykendall/php-domain-parser
===============================

Public Suffix List and IANA Root Zone Database based Domain parsing implemented in PHP.

6.4.0(1y ago)1.2k13.0M—0.3%12620MITPHPPHP ^8.1CI passing

Since Jan 15Pushed 3mo ago29 watchersCompare

[ Source](https://github.com/jeremykendall/php-domain-parser)[ Packagist](https://packagist.org/packages/jeremykendall/php-domain-parser)[ Docs](https://github.com/jeremykendall/php-domain-parser)[ GitHub Sponsors](https://github.com/sponsors/nyamsprod)[ RSS](/packages/jeremykendall-php-domain-parser/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (51)Used By (20)

PHP Domain Parser
=================

[](#php-domain-parser)

**PHP Domain Parser** is a resource based domain parser implemented in PHP.

[![Build Status](https://camo.githubusercontent.com/87614cdb608a25ba584fb5b3a6b5a6f562dcb3b5558c3d2e193291d007ba1d82/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6572656d796b656e64616c6c2f7068702d646f6d61696e2d7061727365722f6275696c642e79616d6c3f6272616e63683d646576656c6f70267374796c653d666c61742d737175617265)](https://github.com/jeremykendall/php-domain-parser/actions?query=workflow%3ABuild)[![Total Downloads](https://camo.githubusercontent.com/75057879de1d7d778e0fd2719f353f1aa76f877232fed642f81ec6de9d7f1595/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6572656d796b656e64616c6c2f7068702d646f6d61696e2d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jeremykendall/php-domain-parser)[![Latest Stable Version](https://camo.githubusercontent.com/66c698353d7f9ad2c30cde46762223a673d639506ae09150e86eba109a5c244b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6a6572656d796b656e64616c6c2f7068702d646f6d61696e2d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://github.com/jeremykendall/php-domain-parser/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/jeremykendall/php-domain-parser/blob/master/LICENSE)

Motivation
----------

[](#motivation)

While there are plenty of excellent URL parsers and builders available, there are very few projects that can accurately parse a domain into its component subdomain, registrable domain, second level domain and public suffix parts.

Consider the domain [www.pref.okinawa.jp](http://www.pref.okinawa.jp). In this domain, the *public suffix* portion is **okinawa.jp**, the *registrable domain* is **pref.okinawa.jp**, the *subdomain* is **www** and the *second level domain* is **pref**.
You can't regex that.

PHP Domain Parser is compliant around:

- accurate Public Suffix List based parsing.
- accurate IANA Top Level Domain List parsing.

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

[](#installation)

### Composer

[](#composer)

```
composer require jeremykendall/php-domain-parser:^6.0

```

### System Requirements

[](#system-requirements)

You need:

- **PHP &gt;= 8.1** but the latest stable version of PHP is recommended
- a copy of the [Public Suffix List](https://publicsuffix.org/) data and/or a copy of the [IANA Top Level Domain List](https://www.iana.org/domains/root/files). Please refer to the [Managing external data source section](#managing-the-package-external-resources) for more information when using this package in production.

Handling of an IDN host requires the presence of the `intl` extension or a polyfill for the `intl` IDN functions like the `symfony/polyfill-intl-idn`otherwise an exception will be thrown when attempting to validate or interact with such a host.

Warning

When upgrading to version `6.4` you MUST refresh your local cache for the fix on private domain resolution to take effect.

Usage
-----

[](#usage)

Warning

If you are upgrading from version 5 please check the [upgrading guide](UPGRADING.md) for known issues.

### Resolving Domains

[](#resolving-domains)

This library can resolve a domain against:

- The [Public Suffix List](https://publicsuffix.org/)
- The [IANA Top Level Domain List](https://www.iana.org/domains/root/files)

In both cases this is done using the `resolve` method implemented on the resource instance. The method returns a `Pdp\ResolvedDomain` object which represents the result of that process.

For the [Public Suffix List](http://publicsuffix.org/) you need to use the `Pdp\Rules` class as shown below:

```
