Page 1 of 1

Ampersand

Posted: Mon Oct 16, 2006 4:59 pm
by CantonDog
I've looked this up but can't seem to find an answer.

Is there any way to deal with an ampersand in a $_GET variable? Noting that there is NOTHING I can do to change the $_GET variable (I can't escape the ampersand or change it in any way)

Here's the breakdown:

The request I'm getting fed is (I'm going to put line feeds in this to make it more readable - in truth it is all one line, I've also made the ampersand bold and red:
[16/Oct/2006:10:35:12 -0600] "GET /nowplaying.php?xml=%0D%0A<audio%20ID=\"id_221631420_29815105\">%0D%0A<type>Song</type>%0D%0A<title>
<![CDATA[I%20Can't%20Go%20For%20That]]></title>%0D%0A<artist><![CDATA[Hall%20&%20Oates]]></artist>%0D%0A<comment1></comment1>%0D%0A
<played_date>10/16/2006</played_date>%0D%0A<played_time>10:35:12</played_time>%0D%0A<length_in_secs>00000223</length_in_secs>%0D%0A
<length>00:03:43</length>%0D%0A</audio>%0D%0A HTTP/1.0" 200 398 "-" "Mozilla/4.0"
Entries without an ampersand get parsed correctly and put into the DB fine. Entries with the ampersand break right after the ampersand.

I can handle everything but the ampersand as I presume that my PHP thinks it's a different variable name beginning after the ampersand.

Is there ANY way around this?

Also, I'm pretty sure that GET is the only way I'm going to be fed this particular var.

Posted: Mon Oct 16, 2006 5:56 pm
by feyd
$_SERVER['QUERY_STRING'] may be of interest.

Posted: Tue Oct 17, 2006 10:19 am
by CantonDog
feyd - Didn't even know that existed... that was exactly what I needed. Thanks a bunch!

Posted: Tue Oct 17, 2006 12:03 pm
by bokehman
Fixing this at this stage is wrong. You need to fix the page that is sending this string. The variable should have been URL encoded at that stage.

Posted: Tue Oct 17, 2006 12:08 pm
by feyd
Something tells me CantonDog may not have control over it.