[SOLVED] Escaped single quote not rendered properly in html

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
User avatar
voltrader
Forum Contributor
Posts: 223
Joined: Wed Jul 07, 2004 12:44 pm
Location: SF Bay Area

[SOLVED] Escaped single quote not rendered properly in html

Post by voltrader »

In an editing screen, I populate forms with previously entered values.

I have set php_value magic_quotes_gpc 0 in .htaccess

Code: Select all

<input type='text' name='title' value='$title' size='50'>
If $title contains an apostrophe and is escaped, like $title='Bob''s' the HTML is still rendered as Bob\.

textarea single quotes render ok:

Code: Select all

<textarea name='title'>$title</textarea>
i.e. Bob's

Anyone know why the escaped single quote in the input=text area is not rendering single quotes?
Last edited by voltrader on Mon Feb 14, 2005 8:47 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Use double quotes for your form tag attributes

Code: Select all

<input type="text" name="title" value="$title" size="50">
otherwise, when you enter the value the HTML will look like this

Code: Select all

<input type='text' name='title' value='Bob''s' size='50'>
See how that will coonfuse the HTML parser. It will think the value attribute finsihes after the backslash becuase escape characters have no effect in HTML
User avatar
voltrader
Forum Contributor
Posts: 223
Joined: Wed Jul 07, 2004 12:44 pm
Location: SF Bay Area

Post by voltrader »

got it... thanks!
Post Reply