Domainparser parses domain registry data and resolves a host name against an IANA TLD list, the Mozilla Public Suffix List, or the ICANN gTLD registry. It supports PHP 8.3 through PHP 8.x and uses Composer for autoloading.
Detailed component documentation is available in docs/.
- Parse IANA TLD, Mozilla Public Suffix List, ICANN gTLD, Root Zone, IDN Table, RDAP bootstrap, and Special-Use registry data.
- Resolve public suffixes, registrable domains, subdomains, TLDs, and gTLD metadata.
- PSL validation with wildcard and exception rules.
- Domain validation with label-level error messages and error codes.
- IDN and punycode-aware host normalization when the PHP IDN extension is available.
- JSON-serializable resolution results for application and API responses.
- Cached registry files with Composer-based registry refresh support.
- Deterministic parser APIs that work with downloaded or bundled registry content.
- Optional DNS lookups that are disabled by default and can be explicitly enabled or forced.
- Bundled serialized registry snapshots for offline inspection and deterministic processing.
composer require codervio/domainparserSee Required packages for runtime and development prerequisites.
Parser accepts registry data separately from the host being resolved. This makes parsing deterministic and allows applications to cache registry data.
use Codervio\Domainparser\Parser;
$parser = new Parser();
$registry = $parser->parseTld("# Version 2024051800\nCOM\nUK\n");
$parser = new Parser((object) ['records' => $registry['records']]);
$parser->setValue('tld');
$domain = $parser->resolve('www.example.uk');
echo $domain->getPublicSuffix(); // uk
echo $domain->getRegistrableDomain(); // example.uk
echo $domain->getSubDomain(); // www
var_dump($domain->exists()); // trueFor a complete public suffix such as co.uk, use the Mozilla suffix registry:
$parser = new Parser();
$parsed = $parser->parseSuffix($mozillaListContents);
$parser = new Parser((object) ['records' => $parsed['records']]);
$parser->setValue('suffix');
$suffix = $parser->resolve('www.example.co.uk');
echo $suffix->getSuffix(); // co.ukThe suffix parser recognizes the ICANN and PRIVATE sections from the Public Suffix List and chooses the longest matching suffix.
$parser = new Parser();
$parsed = $parser->parseGtlds($jsonContents);
$parser = new Parser((object) ['records' => $parsed['records']]);
$parser->setValue('gtlds');
$gtld = $parser->resolve('www.example');
if ($gtld->exists()) {
echo $gtld->getGTLD();
echo $gtld->getRegistryOperator();
}┌──────────────────────────── DNSLookup ────────────────────────────┐
│ Host: example.com │
│ Network: disabled by default — construction makes no DNS request │
├───────────────────────────────────────────────────────────────────┤
│ enable() / activate() Explicitly allow lookups │
│ getAddresses() A and AAAA addresses │
│ getMailServers() MX records │
│ getNameServers() NS records │
│ getTextRecords() TXT records │
│ resolve() Combined DNS summary │
├───────────────────────────────────────────────────────────────────┤
│ Cache: one result per record type for this instance │
│ Offline tests: inject a resolver callback; no public DNS required │
└───────────────────────────────────────────────────────────────────┘
The repository includes cached registry files in src/Registry/:
IANA_TLDS.dat— IANA top-level domains.MOZILLA_PUB_SUFFIX.dat— Mozilla Public Suffix List.IANA_GTLDS.json— ICANN gTLD metadata.IANA_ROOT_ZONE.json— serialized IANA Root Zone Database records.IANA_IDN_TABLES.json— serialized IANA IDN table index.IANA_RDAP_DNS.json— serialized RDAP DNS bootstrap services.IANA_SPECIAL_USE.json— serialized RFC/IANA special-use domain names.
Registry source URLs are exposed as constants on RegistryList:
use Codervio\Domainparser\RegistryList;
RegistryList::IANA_TLDS;
RegistryList::MOZILLA_PUB_SUFFIX;
RegistryList::IANA_GTLDS;
RegistryList::IANA_ROOT_ZONE;
RegistryList::IANA_IDN_TABLES;
RegistryList::IANA_RDAP_DNS;
RegistryList::IANA_SPECIAL_USE;The updatetld Composer command refreshes cached registry files. Network access is required:
composer updatetldcomposer testTests cover registry parsing, domain and suffix resolution, gTLD metadata, DNS behavior, cache persistence, registry refresh dispatch, Unicode host normalization, and failure paths.
Runtime requirements, enforced by Composer:
- PHP extensions:
mbstringandintl. curlis required when using HTTP registry refreshes,Curl, orupdatetld.
For Debian/Ubuntu with PHP 8.3:
sudo apt install php8.3-mbstring php8.3-intl php8.3-curlFor HTML or text coverage reports during development, install PCOV:
sudo apt install php8.3-pcov
php -m | rg pcovDomainparser supports PHP 8.3 through PHP 8.x. Composer enforces this with the ^8.3 platform constraint; PHP 9 is not currently declared as supported.
Verify the active runtime and its required extensions with:
php -v
composer check-platform-reqsInstall the development dependencies before running the static-analysis and formatting tools:
composer installRun PHPStan against the source:
vendor/bin/phpstan analyse src --level=5Preview PHP CS Fixer changes without writing files:
vendor/bin/php-cs-fixer fix src --dry-run --diffApply the formatting changes:
vendor/bin/php-cs-fixer fix src --rules=@PSR12Check PHP Unit:
vendor/bin/phpunit --coverage-textTo run the repository's domain-resolution example:
cd ..
php run.phpMIT. See LICENSE.