ronino: Thanks, I used your code... And modified it too! The following code will only remove the subdomain if it exists... If you run http://domain.com through ronino's code, it would come out as "com". This is a simple fix to check there are more than 2 "bits".
$parseUrl = parse_url(trim($filename));
$bits=explode('.', $parseUrl['host']);
if (count($bits) > 2) {
unset($bits[0]);
}
$domain = implode('.',$bits);
Enjoy ;P
http://kthxbai2u.com/
***Note: The above code only works on single . TLD's (.com, .net, .org) If you get "fasthost.co.uk", it will come out as "co.uk"***
I am working on a fix :)
[EDIT]
I ended up using another code from elsewhere which works flawlessly so far. Here it is:
function getDomain($domainb)
{
$bits = explode('/', $domainb);
if ($bits[0]=='http:' || $bits[0]=='https:')
{
$domainb= $bits[2];
} else {
$domainb= $bits[0];
}
unset($bits);
$bits = explode('.', $domainb);
$idz=count($bits);
$idz-=3;
if (strlen($bits[($idz+2)])==2) {
$url=$bits[$idz].'.'.$bits[($idz+1)].'.'.$bits[($idz+2)];
} else if (strlen($bits[($idz+2)])==0) {
$url=$bits[($idz)].'.'.$bits[($idz+1)];
} else {
$url=$bits[($idz+1)].'.'.$bits[($idz+2)];
}
return $url;
}
kthxbai2u
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0