Need help with TLDExtract?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

218 Stars 24 Forks Apache License 2.0 103 Commits 8 Opened issues


[DEPRECATED] Library for extraction of domain parts e.g. TLD. Domain parser that uses Public Suffix List

Services available


Need anything else?

Contributors list


Consider to use as maintained alternative.


accurately separates the gTLD or ccTLD (generic or country code top-level domain) from the registered domain and subdomains of a URL, e.g. domain parser. For example, say you want just the 'google' part of ''.

Latest Version on Packagist Software License Build Status Coverage Status Total Downloads

Everybody gets this wrong. Splitting on the '.' and taking the last 2 elements goes a long way only if you're thinking of simple e.g. .com domains. Think parsing for example: the naive splitting method above will give you 'co' as the domain and 'uk' as the TLD, instead of 'bbc' and '' respectively.

on the other hand knows what all gTLDs and ccTLDs look like by looking up the currently living ones according to the Public Suffix List. So, given a URL, it knows its subdomain from its domain, and its domain from its country code.
$result = tld_extract('');

object(LayerShifter\TLDExtract\Result)#34 (3) { ["subdomain":"LayerShifter\TLDExtract\Result":private]=> string(11) "" ["hostname":"LayerShifter\TLDExtract\Result":private]=> string(3) "cnn" ["suffix":"LayerShifter\TLDExtract\Result":private]=> string(3) "com" }

implements ArrayAccess interface, so you simple can access to its result.
string(11) ""
string(3) "cnn"
string(3) "com"
Also you can simply convert result to JSON.
string(54) "{"subdomain":"","hostname":"cnn","suffix":"com"}"
This package is compliant with PSR-1, PSR-2, PSR-4. If you notice compliance oversights, please send a patch via pull request.

Does TLDExtract make requests to Public Suffix List website?


uses database from TLDDatabase that generated from Public Suffix List and updated regularly. It does not make any HTTP requests to parse or validate a domain.


The following versions of PHP are supported.

  • PHP 5.5
  • PHP 5.6
  • PHP 7.0
  • PHP 7.1
  • PHP 7.2
  • PHP 7.3
  • HHVM


Via Composer

$ composer require layershifter/tld-extract

Additional result methods


has some usable methods: ```php $extract = new LayerShifter\TLDExtract\Extract();

For domain ''

$result = $extract->parse(''); $result->getFullHost(); // will return (string) '' $result->getRegistrableDomain(); // will return (string) '' $result->isValidDomain(); // will return (bool) true $result->isIp(); // will return (bool) false

For IP ''

$result = $extract->parse(''); $result->getFullHost(); // will return (string) '' $result->getRegistrableDomain(); // will return null $result->isValidDomain(); // will return (bool) false $result->isIp(); // will return (bool) true ```

Custom database

By default package is using database from TLDDatabase package, but you can override this behaviour simply:

new LayerShifter\TLDExtract\Extract(__DIR__ . '/cache/mydatabase.php');
For more details and how keep database updated TLDDatabase.

Implement own result

By default after parse you will receive object of

class, but sometime you need own methods or additional functionality.

You can create own class that implements

and use it as parse result. ```php class CustomResult implements LayerShifter\TLDExtract\ResultInterface {}

new LayerShifter\TLDExtract\Extract(null, CustomResult::class); ```

Parsing modes

Package has three modes of parsing: * allow ICANN suffixes (domains are those delegated by ICANN or part of the IANA root zone database); * allow private domains (domains are amendments submitted to Public Suffix List by the domain holder, as an expression of how they operate their domain security policy); * allow custom (domains that are not in list, but can be usable, for example: example, mycompany, etc).

For keeping compatibility with Public Suffix List ideas package runs in all these modes by default, but you can easily change this behavior: ```php use LayerShifter\TLDExtract\Extract;

new Extract(null, null, Extract::MODEALLOWICANN); new Extract(null, null, Extract::MODEALLOWPRIVATE); new Extract(null, null, Extract::MODEALLOWNOTEXISTINGSUFFIXES); new Extract(null, null, Extract::MODEALLOWICANN | Extract::MODEALLOWPRIVATE); ```

Change log

Please see CHANGELOG for more information what has changed recently.


$ composer test


Please see CONTRIBUTING and CONDUCT for details.


This library is released under the Apache 2.0 license. Please see License File for more information.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.