Quotes in Text Boxes
Moderator: General Moderators
Quotes in Text Boxes
How can I escape quotes in a text box. Everytime I display data to a user that has quotes in it, the rest of the data after the quotes does not show up.
Code: Select all
$string = htmlentities($string);
Last edited by Benjamin on Thu Jul 20, 2006 5:58 pm, edited 1 time in total.
htmlentities will turn a quote into the html version """ if you just want to escape them (by adding a backslash in front) take a look at addslashes()
I think he's talking about an input text box. Adding slashes wouldn't fix it.
You can use to change them back..
You can use
Code: Select all
$varName = html_entity_decode($varName);- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Code: Select all
<input type="text" name="sample" value="Mike said, \"I am escaped\"" />
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
AngryPanda
- Forum Newbie
- Posts: 16
- Joined: Wed Jul 19, 2006 12:18 am
I believe he means...
Although most likely it's in a textarea and not input type text, the point gets across...
Code: Select all
$str = ' oh no " , <this> is going to get "messed up && >>"';
echo '<input type="text" value="' . $str . '">';
# which would break it, so you gotta entities it ( not decode the entities )
echo '<input type="text" value="' . htmlentities($str) . '">';Although most likely it's in a textarea and not input type text, the point gets across...