Form string with '&' sign

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Form string with '&' sign

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Form string with '&' sign

Post by aceconcepts »

The browser will read it literally is an "&" operator and not &

So you should encode it.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: Form string with '&' sign

Post by spacebiscuit »

Ok thanks, is there a function available to do this?

Thanks,

Rob.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Form string with '&' sign

Post by aceconcepts »

urlencode to encode it and urldecode to decode it.
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: Form string with '&' sign

Post by mmj »

aceconcepts wrote:urlencode to encode it and urldecode to decode it.
[encode | decode]URIComponent

are actually the correct functions. :)
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Form string with '&' sign

Post by aceconcepts »

Each to their own. There is never a "correct" one only a wrong one :wink:
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: Form string with '&' sign

Post 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.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: Form string with '&' sign

Post by spacebiscuit »

Thaks that has solved the problem.

Rob.
Post Reply