Regex help

I have coded a system for users to submit their website, if they enter (what they enter -> output):

http://www.site.com/page.html -> site.com
http://www.site.com -> site.com
http://www.site.com/page/page/page.html -> site.com

BUT

If they go

http://www.site.com?=blah

It doesn’t strip to site.com

My code:


$url = clean($_POST['url']);
$url = preg_replace("/http:\\/\\//i", "", $url);
$url = preg_replace("/^www\\./i", "", $url);
$url = preg_replace("/\\/.*/i", "", $url);

[fphp]parse_url/fphp and the PHP_URL_HOST option would be a better way to do this me thinks. :wink:

Exactly what I wanted, thanks again :slight_smile: