Domain Empire

[PHP] TLD List, Inc. Level 2 & 3

Spaceship Spaceship
Watch
Impact
16
Whilst working on a new open-source project I needed to be able to be able to detect/remove the TLD’s from hostnames. This is no easy task algorithmically as example.co.uk (level 2) is just as valid as example.com (level 1) which is also just as valid as example.bob.shiga.jp (level 3), distinguising between what a sub-domain is and a domain that just has a really long ending is difficult.

Long story short I've created a quick script that will process the list from Mozilla into a serialized PHP accessible format. You could then use this list array to check for matches in a domain name for example.

PHP:
<?php
//TLD List Updater (Formats to Serialized PHP)
//Created by Beaver6813 (Beaver6813.com). Big thanks to the Mozilla community!
$tldlist = file("http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1");
$toplist = array();
foreach($tldlist as $key=>$value)
	{
	$value = trim($value);
	if(substr_count($value,"//")==0&&!empty($value))
		{
		if(substr_count($value,".")==0)
			$sublist[$value] = array();
		else
			{
			$dotxplode = explode(".",$value);
			$dotxplode = array_reverse($dotxplode);
			$sublist[$dotxplode[0]][] = $value;
			}
		}
	}
file_put_contents("effective_tld_sublist.dat",serialize($sublist));
?>

NOTE: I'll be including a full lookup function when I've created and tested it ;) I've put a fuller explanation of how to use the list on my blog at
PHP:
 TLD List, Inc. Level 2 & 3*/* Beaver6813.com[/url]

If it helps you, Rep appreciated! :red:
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back