Domain TLD Parser
Parsing URLs in PHP isn’t perfect. Don’t get me wrong here, it does the job when it comes to breaking the URL in logical parts, but, it doesn’t have any options to parse the host into domain name, TLD and sub-domain(s). Most probably because new TLDs are coming out from time to time and they want to avoid having to update that same function with every new TLD release.
To over-come this limitation and because I needed some way of extracting the domain, sub-domain and TLD out of each given URL, I came up with the following class: Domain TLD Parser
It parses hosts with all kinds of different TLDs, even the country-specific ones like ‘.co.za’, ‘.ne.jp’ or ‘.ltd.uk’. Here is an example:
<?php $url = $SERVER[’HTTPREFERER’]; include(’/path/to/domaintldparser.class.php’); $domain = new DomainTldParser; echo ‘<pre>’; print_r($domain->parse($url)); echo ‘</pre>’; ?>
Trackbacks
Use this link to trackback from your own site.

