function fetchLiveDomain($url){
$parts = parse_url($url);
$domain = isset($parts['host']) ? $parts['host'] : '';
if(preg_match('/(?P<domain>[a-z0-9][a-z0-9-]{1,63}.[a-z.]{2,6})$/i', $domain, $regs)){
return $regs['domain'];
}
return FALSE;
}
echo fetchLiveDomain("https://www.pakainfo.com"); // outputs 'pakainfo.com'
echo fetchLiveDomain("http://www.pakainfo.com"); // outputs 'pakainfo.com'
echo fetchLiveDomain("http://mail.pakainfo.co.uk"); // outputs 'pakainfo.co.uk'