Goodness me. Either I'm not understanding this right, or you are all handling this wrong
The below code will take an array of domains in a variety of formats, and will get you just the domain element (i.e. no subdomains, no TLDs).
Let me know how you get on:
PHP Code:
$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");
foreach($domains as $domain) {
if(preg_match("/\.?([a-z0-9-]+)\.co\.[a-z]{2}$/i",$domain,$m)) {
//we've matched a ******.co.** domain
$dom = $m[1];
} 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];
}
echo $domain.': '.$dom.'<br />';
}
Output for the above code:
Quote:
www.test.com: test
www.test2.co.uk: test2
www.test3.info: test3
www.test4.wz: test4
www.test5.museum: test5
http://test6.co.uk: test6
test7.co.uk: test7
http://www.test8.co.uk: test8
|