note 42825 rejected from function.addslashes by betz
| From: | betz@php.net | Date: | Mon, 31 May 2004 08:54:07 +0000 |
| Subject: | note 42825 rejected from function.addslashes by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70331@lists.php.net to get a copy of this message | ||
Note Submitter: a_ at hervard dot net
----
When echoing HTML forms I used to do things like:
echo ("<input type='text' name='meh' value='$meh'>");
This leads to problems, however, because any string that contains an apostrophe ( ' ) will mess
up the form's data. This also become problematic when trying to incorporate Javascript in the
forms, as well. I've just figured out an easy way to fix this, and it's not too entirely
messy:
echo ("<input type=\"text\" name=\"meh\"
value=\"$meh\">");
It might take a bit of getting used to adding a couple of extra keystrokes, but I find it to be well
worth the effort. You don't have to worry about apostophes within values when doing it this
way. The slashes and double-quotation marks ( " ) probably don't really need to be there
when you're not dealing with strings (you could just use a single ( ' ) instead), but by
doing this slashing process to everything it keeps things consistent.