Parsing domain from a URL
$domain = str_ireplace('www.', '', parse_url($url, PHP_URL_HOST));
This would return the google.com
for both http://google.com/... and http://www.google.com/...
Check out parse_url()
:
$url = 'http://google.com/dhasjkdas/sadsdds/sdda/sdads.html';
$parse = parse_url($url);
echo $parse['host']; // prints 'google.com'
parse_url
doesn't handle really badly mangled urls very well, but is fine if you generally expect decent urls.