Forum Moderators: coopster
function getdomain($site) {
preg_match('@^(?:http://)?([^/]+)@i', $site, $matches);
$host = $matches[1];
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
return $matches[0];
}
echo getdomain("google.com");
// returns google.comecho getdomain("www.google.com");
// returns google.comecho getdomain("http://www.google.com");
// returns google.comecho getdomain("google.co.uk");
// returns .co.ukecho getdomain("www.google.co.uk");
// returns .co.ukecho getdomain("http://www.google.co.uk");
// returns .co.uk
function getdomain($site) {
$site = preg_replace('/(http¦ftp)+(?:s)?:(\\/\\/)/i', "", $site);
$site = preg_replace('/www./i', "", $site);
if (strpos($site, "/")!== false) {
$x = explode("/", $site);
$site = $x[0];
}
$site = preg_match('/[^.]+\.[^.]+$/', $site, $matches);
return $matches[0];
}
[edited by: FiRe at 11:40 pm (utc) on Aug. 16, 2006]
Here's an excellent thread on domain/subdomain parsing [webmasterworld.com] that is worth reading.