Forum Moderators: coopster

Message Too Old, No Replies

& in url

&, &, url, php

         

sporb

11:26 am on Jan 18, 2008 (gmt 0)

10+ Year Member



I'm having problems reading & through the url.

if i have a & and i can encode it to %26amp%3B in the url, but it doesn't decode back. so my problem is decoding the %26amp%3B back to &

to encode the url i'm using:

urlencode(htmlspecialchars("this & that"))

this results in "this+%26amp%3B+that" in the url, so i try to decode using:

urlencode(htmlspecialchars($_GET['title']))

but it's not working.

maybe i'm encoding badly? maybe it's just a problem with the decode. i do not want to do any replaces, i would like to encode and decode, so if i'm faced with any other characters in the future, i don't have to add support for them.

any ideas?

venelin13

11:32 am on Jan 18, 2008 (gmt 0)

10+ Year Member



To decode, you should use urldecode()

sporb

11:36 am on Jan 18, 2008 (gmt 0)

10+ Year Member



my mistake, i screwed up on my decoding... the way i'm decoding is:

urldecode(html_entity_decode($_GET['title']));

venelin13

11:43 am on Jan 18, 2008 (gmt 0)

10+ Year Member



Do not use htmlspecialchars() and html_entity_decode() functions.

This should works for you:

<?

$a = urlencode("this & that") ;

$b = urldecode($a);

var_dump($b);

?>

sporb

12:19 pm on Jan 18, 2008 (gmt 0)

10+ Year Member



i've tried, that, didn't work. i'm thinking the problem is with my mod rewrite. the url variable seems to break when it gets to the %20 point.

coopster

9:19 pm on Jan 18, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



In that case you may want to look at the "escaping" flags in mod-rewrite [httpd.apache.org], perhaps you need to apply one or more of them.