PHPackages                             ivankristianto/tld-extract - 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. ivankristianto/tld-extract

ActiveLibrary

ivankristianto/tld-extract
==========================

TLDExtract package forked from layershifter/tld-extract to support PHP 5.4

1.2.5(7y ago)09.5k1Apache-2.0PHPPHP ^5.5.0 || ^7.0

Since Oct 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ivankristianto/TLDExtract)[ Packagist](https://packagist.org/packages/ivankristianto/tld-extract)[ RSS](/packages/ivankristianto-tld-extract/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (19)Used By (0)

TLDExtract
==========

[](#tldextract)

[![Latest Stable Version](https://camo.githubusercontent.com/fcc514ceda1dd038c8848e0d4bb214b3cb9f7a6cad9b48fc7e06edec2b4e99df/68747470733a2f2f706f7365722e707567782e6f72672f6c61796572736869667465722f746c642d657874726163742f762f737461626c65)](https://packagist.org/packages/layershifter/tld-extract)[![Build Status](https://camo.githubusercontent.com/0d293c0c5a70efc5b607f01367cf6000b6f92acad208e2e739f7d10ff749f4fd/68747470733a2f2f7472617669732d63692e6f72672f6c61796572736869667465722f544c44457874726163742e737667)](https://travis-ci.org/layershifter/TLDExtract)[![Total Downloads](https://camo.githubusercontent.com/23b9e113f07b61770e0f419714e6b4d644e27fdd283c9a40359ff89f3f59d836/68747470733a2f2f706f7365722e707567782e6f72672f6c61796572736869667465722f746c642d657874726163742f646f776e6c6f616473)](https://packagist.org/packages/layershifter/tld-extract)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4d616ad1f1c709a855fb718179a435105b2befe8b64b3fede1abddf377e0e3c9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c61796572736869667465722f544c44457874726163742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/layershifter/TLDExtract/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/119e587651eec6bb3a4a276b25ade81092c844b92406ae771c4f1d6ca0c3b9e6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c61796572736869667465722f544c44457874726163742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/layershifter/TLDExtract/?branch=master)

This is a forked from `layershifter/tld-extract` to support PHP 5.4.0.
======================================================================

[](#this-is-a-forked-from-layershiftertld-extract-to-support-php-540)

To support PHP 5.4.0 please use version `^0.2.2` or use the composer command below:

```
composer require ivankristianto/tld-extract "^0.2.2"

```

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

*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 'co.uk' respectively.

`Extract` 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](http://www.publicsuffix.org). So, given a URL, it knows its subdomain from its domain, and its domain from its country code.

```
$result = Extract::get('http://forums.news.cnn.com/');
var_dump($result);

object(LayerShifter\TLDExtract\Result)#34 (3) {
  ["subdomain":"LayerShifter\TLDExtract\Result":private]=>
  string(11) "forums.news"
  ["domain":"LayerShifter\TLDExtract\Result":private]=>
  string(3) "cnn"
  ["tld":"LayerShifter\TLDExtract\Result":private]=>
  string(3) "com"
}

```

`Result` implements ArrayAccess interface, so you simple can access to its result.

```
var_dump($result['subdomain']);
string(11) "forums.news"

var_dump($result['domain']);
string(3) "cnn"

var_dump($result['tld']);
string(3) "com"

```

Also you can simply convert result to JSON.

```
var_dump($result->toJson());
string(54) "{"subdomain":"forums.news","domain":"cnn","tld":"com"}"

```

This package based on code from [w-shadow](http://w-shadow.com/blog/2012/08/28/tldextract/)which is port of [Python module](https://github.com/john-kurkowski/tldextract).

Compatible PHP versions
-----------------------

[](#compatible-php-versions)

- PHP 5.4
- PHP 5.5
- PHP 5.6
- PHP 7
- HHVM

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

[](#installation)

Latest release via Composer:

```
$ composer require layershifter/tld-extract

```

Note About Advanced Usage &amp; Caching
---------------------------------------

[](#note-about-advanced-usage--caching)

- [Advanced usage](#note-advanced)
- [Caching](#note-caching)

###  Advanced usage

[](#-advanced-usage)

For overriding object that will be returned in result you can create own class that implements `\LayerShifter\TLDExtract\Interfaces\ResultInterface`.

For example:

```
class OwnResult implements \LayerShifter\TLDExtract\Interfaces\ResultInterface {
}

Extract::setResultClass('OwnResult');

```

###  Caching

[](#-caching)

By default `TLDExtract` downloads TLD list from publicsuffix.org, caches it and never update.

You can override this behavior via setting $fetch to `true`:

```
Extract::setFetch(true);

```

---

Also, you can manually update TLD cache by calling method (recommended):

```
Extract::updateCache();

```

This method returns boolean that indicates processes result.

---

By default cache file will be stored in `/path/to/TLDExtract/cache/.tld_set`, you can set file for cache by calling:

```
Extract::setCacheFile('/path/to/your/dir/cache.file');

```

License
-------

[](#license)

This project is open-sourced software licensed under the MIT License.

See the LICENSE file for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 86.7% 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 ~71 days

Recently: every ~63 days

Total

18

Last Release

2631d ago

Major Versions

0.2.0 → 1.0.02016-06-20

PHP version history (3 changes)0.1.1PHP &gt;=5.4

1.0.0PHP &gt;=5.5

1.2.0PHP ^5.5.0 || ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6fc4e0b0bbcf6801f4aecdc779950447b43d0cdab3ace3e6ae17ef7c8db5f2ab?d=identicon)[ivankristianto](/maintainers/ivankristianto)

---

Top Contributors

[![layershifter](https://avatars.githubusercontent.com/u/14183168?v=4)](https://github.com/layershifter "layershifter (39 commits)")[![ivankristianto](https://avatars.githubusercontent.com/u/656006?v=4)](https://github.com/ivankristianto "ivankristianto (5 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

domain parserTLDExtract

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/ivankristianto-tld-extract/health.svg)

```
[![Health](https://phpackages.com/badges/ivankristianto-tld-extract/health.svg)](https://phpackages.com/packages/ivankristianto-tld-extract)
```

###  Alternatives

[layershifter/tld-database

Database abstraction for Public Suffix List

632.5M4](/packages/layershifter-tld-database)[bakame/laravel-domain-parser

Laravel package to integrate PHP Domain parser.

26534.8k4](/packages/bakame-laravel-domain-parser)[romeoz/rock-validate

Flexible validator for PHP with I18N.

251.7k6](/packages/romeoz-rock-validate)

PHPackages © 2026

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