https://github.com/utopia-php/domains
Lite & fast micro PHP domain parsing library that is **easy to use**.
https://github.com/utopia-php/domains
hacktoberfest php
Last synced: 20 days ago
JSON representation
Lite & fast micro PHP domain parsing library that is **easy to use**.
- Host: GitHub
- URL: https://github.com/utopia-php/domains
- Owner: utopia-php
- License: mit
- Created: 2020-02-21T06:03:09.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2026-01-12T12:50:55.000Z (about 1 month ago)
- Last Synced: 2026-01-12T15:24:10.479Z (about 1 month ago)
- Topics: hacktoberfest, php
- Language: PHP
- Homepage:
- Size: 2.22 MB
- Stars: 51
- Watchers: 11
- Forks: 21
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Utopia Domains
[](https://travis-ci.com/utopia-php/domains)

[](https://appwrite.io/discord)
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](https://appwrite.io).
Although this library is part of the [Utopia Framework](https://github.com/utopia-php/framework) project, it is completely **dependency-free** and can be used as standalone with any other PHP project or framework.
## Getting Started
Install using composer:
```bash
composer require utopia-php/domains
```
```php
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](https://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:
```bash
php ./data/import.php
```
## Library API
* **get()** - Return you full domain name.
* **getTLD()** - Return only the top-level-domain.
* **getSuffix()** - Return only the public suffix of your domain, for example: co.uk, ac.be, org.il, com, org.
* **getRegisterable()** - Return the registered or registrable domain, which is the public suffix plus one additional label.
* **getName()** - Returns only the registerable domain name. For example, blog.example.com will return 'example', and demo.co.uk will return 'demo'.
* **getSub()** - Returns the full sub domain path for you domain. For example, blog.example.com will return 'blog', and subdomain.demo.co.uk will return 'subdomain.demo'.
* **isKnown()** - Returns true if public suffix is know and false otherwise.
* **isICANN()** - Returns true if the public suffix is found in the ICANN DOMAINS section of the public suffix list.
* **isPrivate()** - Returns true if the public suffix is found in the PRIVATE DOMAINS section of the public suffix list.
* **isTest()** - Returns true if the domain TLD is 'locahost' or 'test' and false otherwise.
> 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.
## Using the Registrar API
The library supports multiple domain registrar adapters:
- **OpenSRS** - OpenSRS domain registrar
- **NameCom** - Name.com domain registrar
### Using OpenSRS Adapter
```php
available($domain);
$purchase = $reg->purchase($domain, [$contact]);
$purchase = $reg->purchase($domain, [$contact], 1);
$suggest = $reg->suggest(['yourname', 'yourname1.com'], ['com', 'net', 'org'], 10, 10000, 100);
$domainDetails = $reg->getDomain($domain);
$renew = $reg->renew($domain, 1);
$transfer = $reg->transfer($domain, [$contact]);
$transfer = $reg->transfer($domain, 'authcode', [$contact]);
```
## Library Registrar API
* **available(string $domain): bool** - Checks to see if a domain is available for registration.
* **purchase(string $domain, array|Contact $contacts, int $periodYears = 1, array $nameservers = []): Registration** - Purchase a domain name and returns a Registration object.
* **suggest(array $query, array $tlds = [], int|null $limit = null, int|null $priceMax = null, int|null $priceMin = null): array** - Suggest or search for domain names.
* **getDomain(string $domain): Domain** - Get domain details and returns a Domain object.
* **renew(string $domain, int $periodYears): Renewal** - Renewal a domain name and returns a Renewal object.
* **transfer(string $domain, string $authCode, array|Contact $contacts, int $periodYears = 1, array $nameservers = []): Registration** - Transfer a domain name and returns a Registration object.
* **getAuthCode(string $domain): string** - Retrieve the authorization code for a domain.
* **checkTransferStatus(string $domain, bool $checkStatus = true, bool $getRequestAddress = false): TransferStatus** - Check the transfer status of a domain.
## System Requirements
Utopia Framework requires PHP 8.2 or later. We recommend using the latest PHP version whenever possible.
## Authors
**Eldad Fux**
+ [https://twitter.com/eldadfux](https://twitter.com/eldadfux)
+ [https://github.com/eldadfux](https://github.com/eldadfux)
## Copyright and license
The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)