cyberfusion / domain-parser
Library to parse domains into their subdomain, SLD, TLD, and registrable domain.
Installs: 3 971
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/cyberfusion/domain-parser
Requires
- php: ^8.3
- desarrolla2/cache: ^3.0
- guzzlehttp/guzzle: ^7.5
- illuminate/support: ^10.4|^11.0|^12.0
- jeremykendall/php-domain-parser: ^6.0
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^10.0|^11.0|^12.0
- symplify/easy-coding-standard: ^12.0
README
Library to parse domains into their subdomain, SLD, TLD, and registrable domain.
This library is a wrapper around jeremykendall/php-domain-parser, focussed on ease of use.
Install
Composer
Run the following command to install the package from Packagist:
composer require cyberfusion/domain-parser
Usage
Example
use Cyberfusion\DomainParser\Parser; $parser = new Parser(); $parsedDomain = $parser->domain('www.cyberfusion.nl'); $parsedDomain->getRegistrableDomain(); // cyberfusion.nl $parsedDomain->getSld(); // cyberfusion $parsedDomain->getTld(); // nl $parsedDomain->hasSubdomain(): // true $parsedDomain->getSubdomain(); // www $parsedDomain->isApexDomain(); // false $parsedDomain->getFqdn(); // www.cyberfusion.nl
Providers
Public Suffix List (recommended)
$parser = new Parser(provider: new PublicSuffixList());
IANA
$parser = new Parser(provider: new IANATopLevelDomainList());
Caching
This package caches data. to prevent too many requests to providers. You can provide your own cache to Parser, or use the included file cache.
For example, use the default cache store in Laravel:
$parser = new Parser( cache: Cache::store(), provider: new PublicSuffixList() );