layershifter/tld-extract
Lightweight PHP library that extracts the top-level domain, domain name, and subdomain from URLs and email addresses using an accurate public suffix list. Simple static API returns structured results, making it easy to validate and parse domains in any Laravel or plain PHP project.
acme.yourapp.com needs to reliably separate the tenant label from the base domain — including for multi-part suffixes like acme.co.uk or shop.example.com.au. Getting this wrong means cross-tenant data leakage or broken routing..example.com versus app.example.com is a security-relevant decision. Naïve "last two labels" logic silently breaks on co.uk, github.io, and other public suffixes — a class of bug that shows up as session bleed between unrelated tenants.www. variants.Do not adopt TLDExtract for new work. The README is marked [DEPRECATED], the repository is archived, the last release was February 2019, and it has zero dependents on the recorded index — a strong signal that the ecosystem has moved on. On any modern Laravel stack (PHP 8.x, Composer 2), expect the practical failure modes of an abandoned 2019 library: stale or incompatible version constraints, no service provider or facade for Laravel, no PHP 8 type-safety, and an unpatched dependency surface.
Consider it only as:
Look elsewhere — or build a thin wrapper — when any of the following hold:
Recommended evaluation path: shortlist a maintained PSL-backed parser (e.g. jeremykendall/php-domain-parser — verify current maintenance, PHP support, and PSL refresh mechanism before committing) and wrap it behind your own small DomainParser interface. The wrapper is the real product decision: it isolates you from whichever underlying library wins, makes the PSL snapshot strategy explicit, and gives you one place to add caching and tests.
For executives: We evaluated an open-source domain-parsing library for an upcoming need — correctly identifying a customer's "real" domain across custom domains, SSO email capture, and per-domain abuse limits. The library is deprecated, archived since 2019, and unmaintained, so we are not taking on that dependency. The underlying need is real and recurring, and getting it wrong has security and data-isolation consequences (cookie scoping, tenant separation). Recommendation: spend a small, bounded effort — roughly a day or two of engineering — to wrap a maintained Public Suffix List parser behind our own interface, with a documented process for refreshing the suffix list. This avoids a recurring class of bugs and prevents three teams from each writing their own regex.
For engineering: This package is a well-shaped API on a dead branch. We're adopting the contract — parse(host) → {suffix, registrableDomain, subdomain} — not the code. Standardize on a maintained PSL-backed parser, wrap it in a single internal service with caching, pin and schedule PSL snapshot updates (treat stale suffix data as a monitored defect, not a footnote), and cover the known-nasty cases in tests: co.uk, github.io, multi-level private suffixes, IDN/punycode, trailing dots, ports, and bare IPs. If TLDExtract already exists anywhere in our codebase, file it as debt with a migration path rather than patching it in place.
How can I help you explore Laravel packages today?