NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page [PHP] TLD List, Inc. Level 2 & 3

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
6 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 06-06-2010, 09:56 AM THREAD STARTER               #1 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 390
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




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


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 Code:
<?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();
????: NamePros.com http://www.namepros.com/code/660180-php-tld-list-inc-level-2-a.html
foreach(
$tldlist as $key=>$value)
    {
    
$value trim($value);
    if(
substr_count($value,"//")==0&&!empty($value))
????: NamePros.com http://www.namepros.com/showthread.php?t=660180
        {
        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

If it helps you, Rep appreciated!
beaver6813 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 07:38 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger