PHP code example of blobfolio / blob-domain

1. Go to this page and download the library: Download blobfolio/blob-domain library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

blobfolio / blob-domain example snippets


// 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

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

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

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

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

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

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

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

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

// 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);