Forum Moderators: coopster

Message Too Old, No Replies

Need to trim a url. what's the best way of doing it?

         

londrum

7:56 pm on May 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hello. got a little problem, hoping someone can help me...

i need to find a way to shorten a text string (which is basically just a url), so that it just says the domain name.
but they are always in different formats though...

http://example.com
http://www.example.com
http://www.example.com/example/
http://www.example.com/example/example.html
http://www.example.com/?a=example

is there a way of shortening them all to just this instead

example.com

using preg_replace, or something like that? i have been fiddling around with it, but the random nature of the urls is throwing me.

cameraman

8:11 pm on May 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about parse_url [us2.php.net]($url,PHP_URL_HOST)

londrum

8:24 pm on May 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...perfect, cheers. and as easy as that!