Forum Moderators: coopster

Message Too Old, No Replies

Get clean url from referrer

I want to strip out everything but the domain name

         

Bonusbana

9:16 am on Jun 17, 2004 (gmt 0)

10+ Year Member



Hi

A simple question: what would be the easiest way to strip an url that looks like this:

http://www.google.se/search?hl=sv&ie=UTF-8&oe=UTF-8&q=cd+omslag&btnG=S%C3%B6k&meta=cr%3DcountrySE

into this:

http://www.google.se

?

Needless to say, it must work with other domain names as well (including stuff like .co.uk)

Any ideas?

thanx
david

dcrombie

10:17 am on Jun 17, 2004 (gmt 0)



The dirname [php.net] function seems to do the trick - not sure if that's the proper use though ;)

brotherhood of LAN

10:20 am on Jun 17, 2004 (gmt 0)

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



or parse url

$uri = parse_url('http://www.google.com/somewhere/?here=1');
print_r($uri);

Array ( [scheme] => http [host] => www.google.com [path] => /somewhere/ [query] => here=1 )

m_shroom

3:34 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



All url's start ...// and.contain.domain.name /
use strpos() to find "//" and "/" then capture text in between.

sned

8:02 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Not an answer .. but another question along the same lines:

How can I get an entire url like www.example.com/page.php#part2

I need the anchor part, seems all the php $_SERVER variables will only return up to page.php, not the whole string. Is there some function I'm missing that will return the whole url?