View Single Post
Old 18-02-2009, 09:22:31 AM     #12 (permalink)
Jeewhizz

 
Join Date: May 2006
Posts: 1,188
Jeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond reputeJeewhizz has a reputation beyond repute

Quote:
Originally Posted by Skinner View Post
Whizz, we are talking about returning ONLY the domain.ext with no subdomains.
That's not what Purg asked:

Quote:
Originally Posted by Jeewhizz View Post
what bit do you want specifically? Just the 'test' in www.test.co.uk ?
Quote:
Originally Posted by purg View Post
Whizz.... Correct
---

To return the domain name, no matter the subdomain level, try this. It's not 100% perfect, but will cover 99% of all domains:

PHP Code:
<?php

$domains 
= array("www.test.com","www.test2.co.uk","www.test3.info","www.test4.wz","www.test5.museum","http://test6.co.uk","test7.co.uk","http://www.test8.co.uk","really.long.sub.domain.here.test9.org.uk");

foreach(
$domains as $domain) {
    if(
preg_match("/\.?([a-z0-9-]+)(\.(co|org|me|ltd|plc)\.[a-z]{2})$/i",$domain,$m)) {
        
//we've matched a ******.co.** domain
        
$dom $m[1];
        
$dom2 $m[1].$m[2];
        
//print_r($m);
    
} else {
        
//treat the domain as a .com/net/org/ws/biz/info
        
preg_match("/\.?([a-z0-9-]+)(\.[a-z]{2,})$/i",$domain,$m);
        
$dom $m[1];
        
$dom2 $m[1].$m[2];
    }
    echo 
$domain.' ==> '.$dom2.' --> '.$dom.'<br />';
}
?>
Quote:
www.test.com ==> test.com --> test
www.test2.co.uk ==> test2.co.uk --> test2
www.test3.info ==> test3.info --> test3
www.test4.wz ==> test4.wz --> test4
www.test5.museum ==> test5.museum --> test5
http://test6.co.uk ==> test6.co.uk --> test6
test7.co.uk ==> test7.co.uk --> test7
http://www.test8.co.uk ==> test8.co.uk --> test8
really.long.sub.domain.here.test9.org.uk ==> test9.org.uk --> test9
Jeewhizz is offline