2, 'uk' => 3, 'com' => 2); function get_domain($host) { global $domain_depth; $parts = explode('.', $host); return implode('.', array_slice($parts, count($parts) - $domain_depth[$parts[count($parts)-1]])); } function test($host) { $domain = get_domain($host); echo "$host -> $domain\r\n"; } test('www.xxx.dk'); test('www.xxx.co.uk'); test('www.xxx.com'); ?>