...

View Full Version : need help with urlencode



koolaid
10-07-2007, 09:26 AM
Is it possible to urlencode a URL via $_GET? Cause i've tried it..... doesn't seem to work, while $_POST works perfectly.

I've noticed the character '#' being left out (and everything behind it) e.g. www.domain.com/files/list.htm#thelist , so 'thelist' dissapears including the '#'.


$url = urlencode($_GET['url'])


Anyone?

kbluhm
10-07-2007, 03:51 PM
That code will encode a variable named in a query string like so:
http://www.whatever.com/page.php?url=something&another=nothing

I don't think you understand exactly what the $_GET array consists of. You may be wanting to use $_SERVER['REQUEST_URI']

koolaid
10-07-2007, 06:39 PM
That code will encode a variable named in a query string like so:
http://www.whatever.com/page.php?url=something&another=nothing

I don't think you understand exactly what the $_GET array consists of. You may be wanting to use $_SERVER['REQUEST_URI']

Well, correct me if i'm wrong, but $_GET['url'] gets the string from ?url e.g. ?url=www.somethingblah.com right? I'm somewhat confused right now...

Mwnciau
10-07-2007, 07:04 PM
Try rawurlencode instead.

koolaid
10-07-2007, 07:29 PM
Try rawurlencode instead.

Hmm that didn't work either, it doesn converts all other chars EXCEPT '#'... damn that '#' is a pain in the *** lol, looks like PHP just sees '#' as a comment (and ignores the rest) when recieved via the browser.

Mwnciau
10-07-2007, 07:34 PM
str_replace('#', '%23', urlencode($string));

koolaid
10-07-2007, 07:39 PM
str_replace('#', '%23', urlencode($string));

Again... no luck

current code:


$url = $_GET['url'];
$url = str_replace('#', '%23', urlencode($url));

It does convert ':' and '/' from http:// nicely, but when it comes to '#' it totally ignores it... odd

Mwnciau
10-07-2007, 07:44 PM
Just tried it and just urlencode on it's own works fine for me

Inigoesdr
10-07-2007, 09:57 PM
I don't think the pound (#), or anything after it is even sent to the server. It's used by the browser to jump to an anchor.

koolaid
10-08-2007, 07:33 PM
I don't think the pound (#), or anything after it is even sent to the server. It's used by the browser to jump to an anchor.

Is this right? Because i am thinking the same way... can anyone confirm this? (That the server cannot recieve '#' from the browser)

Inigoesdr
10-08-2007, 09:34 PM
Yeah, I was right. You can test it(I did) or do a search and find some links with confirmation:

http://www.webmasterworld.com/forum92/528.htm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum