473,396 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

preg_replace help?

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
3 1513
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JDJones | last post by:
I'm having some trouble getting this replacement to work efficiently. I have the following code: $thing = preg_replace("(\r\n|\n|\r|\t)", "", $thing1); What I want to do now is to get it to...
4
by: Sidharta | last post by:
Hi all, how come this doesn't work????? # convert to unix new lines $text = preg_replace("/\r\n/", "\n", $text); # remove extra new lines $text = preg_replace("/\n+/", "\n", $text); is...
3
by: TXSherry | last post by:
Hi, I cannot seem to wrap my brain around preg_replace. Though I've read the help file backwords and forwards. :/ Hoping someone can give me a solution here. Problem: Given string 'str'...
1
by: yawnmoth | last post by:
say i have the following script: <? $test = "aaaaa"; print '"' . preg_replace('/.*/','x',$test) . '"<br>'; $test = "\n\n\n\n\n"; print '"' . preg_replace('/.*/','x',$test) . '"'; ?> the...
7
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore...
2
by: Fotozine | last post by:
well, I have this peace of code which isn't woking as I would like it to work. $tekst = preg_replace('/\\\"/', '&quot;', $tekst); In my forms, I would like to change " to &quot; but this line is actualy...
3
by: Charles | last post by:
I'm new to this regular expression stuff. I'd like to use preg_replace to eliminate a known multi-line signature from the body of an E-mail. Say the body text is in $body, and the sig is this ...
1
by: K. | last post by:
Hello! I would like to use preg_replace function to leave in the result variable only: 1) letters from A to Z including Polish letters like ±¶¼³óñê including Polish upper letters like ¡¦¬£ÓÑÊ...
1
by: Sbudah | last post by:
Hi All, I have relatively moderate experience with PHP but preg_replace is not one of my strong points. I need HELP with the following: I have 5 <div> tags whose values are sent to a PHP page...
5
by: helraizer1 | last post by:
Hey folks and folksesses, I have written some code to get emoticons onto my image based shoutbox but there is quite a large bug, as there is with any code in the early stages, and I need your help...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.