Giter Site home page Giter Site logo

domains's Introduction

Utopia Domains

Build Status Total Downloads 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.

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.

Getting Started

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

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 regiterable 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.

System Requirements

Utopia Framework requires PHP 7.4 or later. We recommend using the latest PHP version whenever possible.

Authors

Eldad Fux

Copyright and license

The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php

domains's People

Contributors

eldadfux avatar 1nf3rn0-h avatar donaldtrump88 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.