PHPackages                             blobfolio/blob-domain - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. blobfolio/blob-domain

AbandonedArchivedLibrary[Validation &amp; Sanitization](/categories/validation)

blobfolio/blob-domain
=====================

Parse and validate domain names.

8.0.0(8y ago)15.9k2WTFPLPHPPHP &gt;= 7.0

Since Mar 25Pushed 6y ago2 watchersCompare

[ Source](https://github.com/Blobfolio/blob-domain)[ Packagist](https://packagist.org/packages/blobfolio/blob-domain)[ Docs](https://github.com/Blobfolio/blob-domain)[ RSS](/packages/blobfolio-blob-domain/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (2)

blob-domain
===========

[](#blob-domain)

blob-domain is a simple PHP library for parsing and validating domain names. It supports the full [Public Suffix](https://publicsuffix.org/list/) ruleset, translates Unicode to ASCII or vice versa (if the PHP extension INTL is present), and can break down a host into its constituent parts: subdomain, domain, and suffix.

[![Build Status](https://camo.githubusercontent.com/6e5c218403d133e65f2c533e39fc45398aacf1c244fb4120fc2ee29441c6111d/68747470733a2f2f7472617669732d63692e6f72672f426c6f62666f6c696f2f626c6f622d646f6d61696e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Blobfolio/blob-domain)

Table of Contents
-----------------

[](#table-of-contents)

1. [Requirements](#requirements)
2. [Installation](#installation)
3. [Reference](#reference)

- [::parse\_host()](#parse_host)
- [::parse\_host\_parts()](#parse_host_parts)
- [is\_valid()](#is_valid)
- [is\_ascii()](#is_ascii)
- [is\_fqdn()](#is_fqdn)
- [is\_ip()](#is_ip)
- [is\_unicode()](#is_unicode)
- [has\_dns()](#has_dns)
- [strip\_www()](#strip_www)

4. [License](#license)

Requirements
------------

[](#requirements)

blob-domain and its dependencies require PHP 7.0+ with the following modules:

- BCMath
- DOM
- Fileinfo
- Filter
- JSON
- MBString
- INTL

Installation
------------

[](#installation)

Use Composer:

```
composer require "blobfolio/blob-domain:dev-master"
```

Reference
---------

[](#reference)

First up, the basics.

### Basic Usage:

[](#basic-usage)

```
// Initialize the object by passing a host-like string.
$domain = new blobfolio\domain\domain('www.Google.com');

// Access the sanitized host by typecasting as a string.
echo (string) $domain; //www.google.com

// Get it all. If a part is not applicable, its value will be NULL.
$data = $domain->get_data();
/*
array(
    host => www.google.com
    subdomain => www
    domain => google
    suffix => com
)
*/

// Or each part using `get_KEY()`.
echo $domain->get_host(); //www.google.com
echo $domain->get_subdomain(); //www
echo $domain->get_domain(); //google
echo $domain->get_suffix(); //com

// By default, Unicode domains are converted to ASCII.
$domain = new blobfolio\domain\domain('http://☺.com');
echo $domain->get_host(); //xn--74h.com

// Convert them back by passing `TRUE` to the getters.
echo $domain->get_host(true); //☺.com
```

The following static methods exist if you don't want to initialize an object.

### ::parse\_host()

[](#parse_host)

Parse the hostname part of an arbitrary string, which might be a hostname, IP address, URL, etc.

Note: this will convert Unicode to ASCII.

#### Arguments

[](#arguments)

- (*string*) Host

#### Returns

[](#returns)

Returns the processed hostname or `FALSE` on failure.

#### Example

[](#example)

```
$foo = blobfolio\domain\domain::parse_host('http://☺.com'); //xn--74h.com
$foo = blobfolio\domain\domain::parse_host('co.uk'); //FALSE
```

### ::parse\_host\_parts()

[](#parse_host_parts)

Pull out the different parts of a host name, i.e. what you'd get running `get_data()` on a `domain` object.

Note: this will convert Unicode to ASCII.

#### Arguments

[](#arguments-1)

- (*string*) Host

#### Returns

[](#returns-1)

Returns an array containing the processed parts or `FALSE` on failure.

#### Example

[](#example-1)

```
$foo = blobfolio\domain\domain::parse_host_parts('www.Google.com');
/*
array(
    host => www.google.com
    subdomain => www
    domain => google
    suffix => com
)
*/
```

The object also comes with public methods. Aside from the various `get_*()` functions already demonstrated, you've got the following.

### is\_valid()

[](#is_valid)

Is the host valid? This will be `TRUE` unless:

- The host string is malformed;
- The host string contains Unicode and the INTL extension is missing;
- The host contains no domain portion;
- The `$dns` option is passed but the host is not a FQDN or is missing an `A` record;

#### Arguments

[](#arguments-2)

- (*bool*) (*optional*) Reachable DNS. If `TRUE`, the host must either be a public IP address or have an `A` record in its DNS table. Default: `FALSE`

#### Returns

[](#returns-2)

Returns `TRUE` or `FALSE`.

### is\_ascii()

[](#is_ascii)

Whether or not a host is ASCII, like `google.com`. Unicode domains are still a bit unknown in many parts of the Western world and can cause problems with native PHP functions or databases, so good to know what you've got.

Note: IP addresses are considered ASCII for the purposes of this function.

Note: The various `get_*()` functions will always return the host in ASCII format by default. Passing `TRUE` to those functions will return Unicode hosts in their original Unicode, e.g. `☺.com`.

#### Arguments

[](#arguments-3)

N/A

#### Returns

[](#returns-3)

Returns `TRUE` or `FALSE`.

#### Example

[](#example-2)

```
// ☺.com
$domain->is_ascii(); //FALSE

// xn--74h.com
$domain->is_ascii(); //FALSE

// google.com
$domain->is_ascii(); //TRUE
```

### is\_fdqn()

[](#is_fdqn)

Checks to see whether the host is a Fully-Qualified Domain Name (or at least a public IP address). In other words, can it be seen by the outside world?

Note: this does not imply the host actually exists.

#### Arguments

[](#arguments-4)

N/A

#### Returns

[](#returns-4)

Returns `TRUE` or `FALSE`.

### is\_ip()

[](#is_ip)

Is the host an IP address?

#### Arguments

[](#arguments-5)

- (*bool*) (*optional*) Allow restricted/private. Default: `TRUE`

#### Returns

[](#returns-5)

Returns `TRUE` or `FALSE`.

### is\_unicode()

[](#is_unicode)

Whether or not a host is Unicode, like `☺.com`. Unicode hosts can cause problems with native PHP functions and databases, so might be a good thing to know.

Note: The various `get_*()` functions will return an ASCIIfied version of a Unicode domain by default, like `xn--74h.com`. Passing `TRUE` will de-convert them back to the original Unicode.

#### Arguments

[](#arguments-6)

N/A

#### Returns

[](#returns-6)

Returns `TRUE` or `FALSE`.

#### Example

[](#example-3)

```
// ☺.com
$domain->is_unicode(); //TRUE

// xn--74h.com
$domain->is_unicode(); //TRUE

// google.com
$domain->is_unicode(); //FALSE
```

### has\_dns()

[](#has_dns)

Does this host have an `A` record in its DNS table or is it a public IP address?

Note: the `A` record cannot point to a restricted/reserved IP like `127.0.0.1` or the function will return `FALSE`.

#### Arguments

[](#arguments-7)

N/A

#### Returns

[](#returns-7)

Returns `TRUE` or `FALSE`.

### strip\_www()

[](#strip_www)

This removes the leading `www.` subdomain, if any, from the parsed result. You can also have this run automatically at initialization by passing a second argument to the constructor, `TRUE`.

#### Arguments

[](#arguments-8)

N/A

#### Returns

[](#returns-8)

Returns `TRUE` or `FALSE`, indicating whether or not a change was made.

#### Example

[](#example-4)

```
// As separate actions.
$foo = new blobfolio\domain\domain('www.Google.com');
/*
array(
    host => www.google.com
    subdomain => www
    domain => google
    suffix => com
)
*/
$foo->strip_www();
/*
array(
    host => google.com
    subdomain => NULL
    domain => google
    suffix => com
)
*/

// Or you can do this at initializing by passing TRUE as a second argument.
$foo = new blobfolio\domain\domain('www.Google.com', true);
```

License
-------

[](#license)

Copyright © 2018 [Blobfolio, LLC](https://blobfolio.com) &lt;&gt;

This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2.

```
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.

```

### Donations

[](#donations)

   [![Bitcoin QR](https://camo.githubusercontent.com/02c1aab6dc8b7908cb540a77b3df80ff1781b137aa6e4de8e795aac613ffe124/68747470733a2f2f626c6f62666f6c696f2e636f6d2f77702d636f6e74656e742f7468656d65732f62332f7376672f6274632d6769746875622e737667)](https://camo.githubusercontent.com/02c1aab6dc8b7908cb540a77b3df80ff1781b137aa6e4de8e795aac613ffe124/68747470733a2f2f626c6f62666f6c696f2e636f6d2f77702d636f6e74656e742f7468656d65732f62332f7376672f6274632d6769746875622e737667) If you have found this work useful and would like to contribute financially, Bitcoin tips are always welcome!

**1Af56Nxauv8M1ChyQxtBe1yvdp2jtaB1GF**

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~74 days

Recently: every ~108 days

Total

7

Last Release

2930d ago

Major Versions

0.4.2 → 8.0.02018-06-17

PHP version history (2 changes)0.1PHP &gt;= 7.0

0.3PHP &gt;= 5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/403248?v=4)[Josh](/maintainers/joshstoik1)[@joshstoik1](https://github.com/joshstoik1)

---

Top Contributors

[![joshstoik1](https://avatars.githubusercontent.com/u/403248?v=4)](https://github.com/joshstoik1 "joshstoik1 (90 commits)")

---

Tags

domain-namesdomain-parsingdomain-validationphppublic-suffix-listphpidnformattingdomaintldPublic Suffix Listianaicann

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/blobfolio-blob-domain/health.svg)

```
[![Health](https://phpackages.com/badges/blobfolio-blob-domain/health.svg)](https://phpackages.com/packages/blobfolio-blob-domain)
```

###  Alternatives

[jeremykendall/php-domain-parser

Public Suffix List and IANA Root Zone Database based Domain parsing implemented in PHP.

1.2k13.6M100](/packages/jeremykendall-php-domain-parser)[io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

4842.6M12](/packages/io-developer-php-whois)[surgiie/transformer

A data transforming/formatting package for php.

12625.6k1](/packages/surgiie-transformer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
