Here's a function I use to get only the domain from a URL.. I think that's what you're after? Just pass it a url and it will return the domain.
Code:
function getdomain($url)
{
// patterns we need to match
$pattern_hostname = '/^(http:\/\/)?([^\/]+)/i';
$pattern_domain = '/[^\.\/]+\.[^\.\/]+(\.[^\.\/]{2})?$/';
// extract hostname from URL string
@preg_match($pattern_hostname, $url, $matches);
$hostname = $matches[2];
// extract sld.tld(.cctld if exists)
@preg_match($pattern_domain, $hostname, $matches);
$domain = $matches[0];
return $domain;
}
The only thing is.. it can't differentiate between a domain and an IP - if you pass it an IP, it gives you the last 2 octets as the domain. It would be easy enough to validate that before or after you use the function though.
Hope this helps..
QD