I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 7974
40801 credits Members referred : 3
« Reply #1 on: Jul 28, 2006, 02:17:47 PM »
I am not sure for the full text, but if you want to make this query faster you can break the domain to 3 fields (subdomain, domain, tld) and make them index
I am not sure for the full text, but if you want to make this query faster you can break the domain to 3 fields (subdomain, domain, tld) and make them index
I am not sure for the full text, but if you want to make this query faster you can break the domain to 3 fields (subdomain, domain, tld) and make them index
Hey Nick,
I checked this but how do you parse an unkown domain name format like domain.com or domain.co.uk or sub.domain.co.uk
to resolve the three parts? checking the last part against 280 tld's?
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 7974
40801 credits Members referred : 3
« Reply #18 on: Jul 29, 2006, 12:44:42 PM »
I will try to make this with pseudo - php code :
Code:
<?php
$domain = 'whatever.com';
$sql->query ( "SELECT tld FROM tlds ORDER BY LENGTH DESC" );//Meaning that it will give first the co.uk and then the uk while ( $sql->next() ) { if ( substr ( $domain, -1, strlen( $sql['tld'] ) = $sql['tld'] ) { //You found the tld $domainLeft = substr ( $domain, 0, ( strlen($sql['tld'] - strlen($domain) + 1 )); // It will left the whatever, without the extension and the . if ( strpos ( $domainLeft, '.' ) === false ) //It has subdomain { $subDomain = ''; $finalDomain = $domainLeft; }else{ $subDomain = explode ( '.', $domainLeft ); $finalDomain = array_pop ( $subDomain ); $subDomain = implode ( '.', $subDomain ); } } }
I am not sure if it is working, but the logic is correct (or I have to drink another coffee to think it better )
« Last Edit: Jul 29, 2006, 12:47:35 PM by Nikolas »
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6280
38506 credits Members referred : 374
It's time to use PHP5!
« Reply #19 on: Jul 29, 2006, 02:50:10 PM »
Hey Nick,
Thank you that brings back the development time for this feature to only a few hours
after some modification, this is the result:
Code:
<?php $domain = "mail.finalwebsites.co.uk";
$res = mysql_query("SELECT tld FROM domain_info ORDER BY LENGTH(tld) DESC"); //Meaning that it will give first the co.uk and then the uk while ($arr = mysql_fetch_assoc($res)) { $tmp_tld = substr($domain, -strlen($arr['tld'])); if ($tmp_tld == $arr['tld']) { // You found the tld $tld = $arr['tld']; $domainLeft = substr($domain, 0, -(strlen($tld) + 1)); // It will left the whatever, without the extension and the . if (strpos($domainLeft, ".") === false) { // It hasn't a subdomain $subDomain = ""; $finalDomain = $domainLeft; } else { $domain_parts = explode(".", $domainLeft); $finalDomain = array_pop($domain_parts); // select the domain and remove it from the array $subDomain = implode(".", $domain_parts); // a subdomain can more then one parts seperated with dot's } echo "The tld is: ".$tld."<br>"; echo "the domain name is :".$finalDomain."<br>"; echo "the subdomain is: "; echo (!empty($subDomain)) ? $subDomain : "n/a"; echo "<br>"; break; } }
by the way this function is a rare one (searched already the internet for a while). I like to post this script to the tutorial section, what about the tld table? Maybe we should send this data on request? (to members only)