why are you trying to use regex? many of your own functions are available for you, such as:
$host = parse_url($url, PHP_URL_HOST);
upgrade, let it go, may need to improve, but better than regex imo
function determainDomainName($url) { $hostname = parse_url($url, PHP_URL_HOST); $parts = explode(".",$hostname); switch(count($parts)) { case 1: return $parts[0];
Add the following 2 functions to your libraries, etc.
Then use like this:
$urls = array( 'http://www.google.com/tomato', 'http://int.google.com', 'http://google.co.uk' ); foreach($urls as $url) { echo determainDomainName($url) . "\n"; }
They all will google echo
see @ http://codepad.org/pA5KWckb
RobertPitt
source share