Lite & fast micro PHP domain parsing library that is **easy to use**.
MIT License
Utopia Domains library is a simple and lite library for parsing domain names structure. This library is aiming to be as simple and easy to learn and use. This library is maintained by the Appwrite team.
Although this library is part of the Utopia Framework project, it is completely dependency-free and can be used as standalone with any other PHP project or framework.
Install using composer:
composer require utopia-php/domains
<?php
require_once '../vendor/autoload.php';
use Utopia\Domains\Domain;
// demo.example.co.uk
$domain = new Domain('demo.example.co.uk');
$domain->get(); // demo.example.co.uk
$domain->getTLD(); // uk
$domain->getSuffix(); // co.uk
$domain->getRegisterable(); // example.co.uk
$domain->getName(); // example
$domain->getSub(); // demo
$domain->isKnown(); // true
$domain->isICANN(); // true
$domain->isPrivate(); // false
$domain->isTest(); // false
// demo.localhost
$domain = new Domain('demo.localhost');
$domain->get(); // demo.localhost
$domain->getTLD(); // localhost
$domain->getSuffix(); // ''
$domain->getRegisterable(); // ''
$domain->getName(); // demo
$domain->getSub(); // ''
$domain->isKnown(); // false
$domain->isICANN(); // false
$domain->isPrivate(); // false
$domain->isTest(); // true
Utopia Domains parser uses a public suffix PHP dataset auto-generated from the publicsuffix.org. The dataset get periodically updates from us, but you can also manually update it by cloning this library and running the import script with the import command:
php ./data/import.php
If you want to parse ordinary web urls then use
$host = parse_url($return, PHP_URL_HOST); $domain = new Utopia\Domains\Domain($host);
to get the domain object.
<?php
use Utopia\Domains\Registrar;
use Utopia\Domains\Contact;
use Utopia\Domains\Registrar\OpenSRS;
$opensrs = new OpenSRS(
'apikey',
'apisecret',
'username',
'password',
[
'ns1.nameserver.com',
'ns2.nameserver.com',
]
);
$reg = new Registrar($opensrs);
$contact = new Contact(
'firstname',
'lastname',
'phone',
'email',
'address1',
'address2',
'address3',
'city',
'state',
'country',
'postalcode',
'org',
'owner',
);
$domain = 'yourname.com';
$available = $reg->available($domain);
$purchase = $reg->purchase($domain, $contact);
$suggest = $reg->suggest(['yourname', 'yourname1.com'], ['com', 'net', 'org']);
$domainDetails = $reg->getDomain($domain);
$renew = $reg->renew($domain, 1);
$transfer = $reg->transfer($domain, [$contact]);
Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.
Eldad Fux
The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php