It'd be great to have the code in PHP - could you try your hand at translating it? The Ruby code is:
<%
def extractDomainName(url)
r = url=~(/^(?:\w+:\/\/)?([^\/?]+)(?:\/|\?|$)/) ? $1 : 'Not a valid URL!'
r.gsub!(/((?:www)|(?:seek)|(?:query)|(?:search))\.(([^\.]+)\.([^\.]+)(\.([^\.]+))?)/, '\2')
r.gsub!(/\:\d+$/, '')
r
end
require "cgi"
cgi = CGI.new
puts extractDomainName(cgi["url"])
%>
I tried converting it to PHP but it wasn't passing all of the tests shown on the man page, so it needs some more work:
$url = preg_replace('/^(?:\w+:\/\/)?([^\/?]+)(?:\/|\?|$)/', '\1', $url);
$url = preg_replace('/((?:www)|(?:seek)|(?:query)|(?:search))\.(([^\.]+)\.([^\.]+)(\.([^\.]+))?)/', '\2', $url);
$url = preg_replace('/\:\d+$/', '', $url);
echo $url;
Jonathan