By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

preg_replace help?

P: n/a
Im accepting user input from a text-box on a webpage.
I am then wanting to echo that back into the same box when the page is
submitted.

The problem I have is that the input COULD contain multiple quotes and
double-quotes.
AddSlashes doesnt seem to work properly, as it turns ' into \'
....and " just into \ (removing everything after)

I thought of using single-quotes for the Value='' and then use preg_replace
to replace all occurances of ' with \' ...but I cant figure-out how to do
it.

Anyone got any idea?

For example the user might have entered: ''''"""'"'"''"' (A collection of
quotes & double-quotes)
The input is stored in $myVar... and needs to be put BACK inside Value=''

Jul 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Rik
On Sat, 28 Jul 2007 04:11:02 +0200, Trammel <Me@Server.comwrote:
Im accepting user input from a text-box on a webpage.
I am then wanting to echo that back into the same box when the page is
submitted.

The problem I have is that the input COULD contain multiple quotes and
double-quotes.
AddSlashes doesnt seem to work properly, as it turns ' into \'
...and " just into \ (removing everything after)
It doesn't, but you haven't shown your code and exact output, so I cannot
tell you what the error there is.
I thought of using single-quotes for the Value='' and then use
preg_replace
to replace all occurances of ' with \' ...but I cant figure-out how to
do
it.

Anyone got any idea?

For example the user might have entered: ''''"""'"'"''"' (A collection
of
quotes & double-quotes)
The input is stored in $myVar... and needs to be put BACK inside Value=''
If it's just HTML, use htmlspecialchars($myVar,ENT_QUOTES); On a submit of
the form it will be the normal string again, so no worries there either.
--
Rik Wasmus
Jul 28 '07 #2

P: n/a
"Rik" <lu************@hotmail.comwrote in message
news:op.tv5klmtiqnv3q9@metallium...
On Sat, 28 Jul 2007 04:11:02 +0200, Trammel <Me@Server.comwrote:
>Im accepting user input from a text-box on a webpage.
I am then wanting to echo that back into the same box when the page is
submitted.

The problem I have is that the input COULD contain multiple quotes and
double-quotes.
AddSlashes doesnt seem to work properly, as it turns ' into \'
...and " just into \ (removing everything after)

It doesn't, but you haven't shown your code and exact output, so I cannot
tell you what the error there is.
>I thought of using single-quotes for the Value='' and then use
preg_replace
to replace all occurances of ' with \' ...but I cant figure-out how to
do
it.

Anyone got any idea?

For example the user might have entered: ''''"""'"'"''"' (A collection
of
quotes & double-quotes)
The input is stored in $myVar... and needs to be put BACK inside Value=''

If it's just HTML, use htmlspecialchars($myVar,ENT_QUOTES); On a submit of
the form it will be the normal string again, so no worries there either.
htmlspecialchars($myVar) worked great, thanks :-)
Jul 28 '07 #3

P: n/a
htmlspecialchars($myVar) worked great, thanks :-)
Just a note, does your server have magic_quotes_gpc enabled, if so that
could have been causing you problems (you can either turn it off or use
stripslashes).
Jul 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.