473,383 Members | 1,759 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,383 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 1511
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.