Page 1 of 1

Form string with '&' sign

Posted: Mon Nov 17, 2008 8:26 am
by spacebiscuit
Hi,

I am using a form to capture user input. I have noticed that if the user includes the '&' sign in an input string in causes a termination of the data string which is sent to the target script.

For example if the input was: "This is a test of the & sign"

The variable receiving this string would read as: "This is a test of the"

Is it first necessary to encode the string?

Thanks in advance,

Rob.

Re: Form string with '&' sign

Posted: Mon Nov 17, 2008 8:46 am
by aceconcepts
The browser will read it literally is an "&" operator and not &

So you should encode it.

Re: Form string with '&' sign

Posted: Mon Nov 17, 2008 8:51 am
by spacebiscuit
Ok thanks, is there a function available to do this?

Thanks,

Rob.

Re: Form string with '&' sign

Posted: Mon Nov 17, 2008 9:06 am
by aceconcepts
urlencode to encode it and urldecode to decode it.

Re: Form string with '&' sign

Posted: Mon Nov 17, 2008 9:20 am
by mmj
aceconcepts wrote:urlencode to encode it and urldecode to decode it.
[encode | decode]URIComponent

are actually the correct functions. :)

Re: Form string with '&' sign

Posted: Mon Nov 17, 2008 9:33 am
by aceconcepts
Each to their own. There is never a "correct" one only a wrong one :wink:

Re: Form string with '&' sign

Posted: Mon Nov 17, 2008 10:53 am
by mmj
aceconcepts wrote:Each to their own. There is never a "correct" one only a wrong one :wink:

Oops! :banghead:

For some reason I thought you were talking about JavaScript, I read escape & unesacpe.

Re: Form string with '&' sign

Posted: Mon Nov 17, 2008 12:58 pm
by spacebiscuit
Thaks that has solved the problem.

Rob.