Domain name value object
<?php
use \Rincler\Domain\Domain;
$domain = new Domain('sub.domain.com');
echo $domain; // sub.domain.com
echo $domain->asIdn(); // sub.domain.com
echo $domain->asPunycode(); // sub.domain.com
echo $domain->getZone(); // domain.com
echo $domain->getWithoutZone(); // sub
echo $domain->getTld(); // com
echo $domain->getWithoutTld(); // sub.domain
echo $domain->getLevel(); // 3
$domain = new Domain('домен.рф');
echo $domain->asIdn(); // домен.рф
echo $domain->asPunycode(); // xn--d1acufc.xn--p1ai
$domain = new Domain('xn--d1acufc.xn--p1ai');
echo $domain->asIdn(); // домен.рф
echo $domain->asPunycode(); // xn--d1acufc.xnn
composer require rincler/domain
- static
isValid(): bool
- Returnstrue
if domain is valid, returnsfalse
otherwise __constructor(string $domain)
- The constructor validates domain (throwsInvalidDomainException
if domain is not valid) and creates object of domainasIdn(): string
- Returns domain as IDN stringasPunycode(): string
- Returns domain as Punycode stringgetLevel(): int
- Returns domain levels countgetZone(): Domain
- Returns zone of domaingetWithoutZone(): Domain
- Returns domain without zonegetTld(): Domain
- Returns top-level domaingetWithoutTld(): Domain
- Returns domain without top-level domainequals(Domain $domain): bool
- Returnstrue
if current domain equals checked domain, returnsfalse
otherwise__toString(): string
- Analog forgetIdn
Validation of domain in intl extension fixed in 7.3.0. See http://bugs.php.net/76829
This library is released under the MIT license.