Re: textarea form input converting < and > to < >
| From: | Jim Winstead | Date: | Wed, 20 Feb 2002 20:59:55 +0000 |
| Subject: | Re: textarea form input converting < and > to < > | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-85595@lists.php.net to get a copy of this message | ||
Byron Albert <balbert@internet.com> wrote:
> I have a few forms that are used to input html. We have run into a
> problem of < and > getting turned into < and > when you hit
> submit, Or if you hit submit more than once. I have attached a sample
> form. The major problem here is that some times we want < and some
> times we want to input html tags. Has any one else run into this problem
> maybe even found a solution.
when you re-display user input in a textarea (or as the value
attribute of a text input field), you should use the htmlentities()
function. so, from your code:
> <TEXTAREA NAME=test rows=10 cols=50><? echo $test; ?></textarea>
should be:
> <TEXTAREA NAME=test rows=10 cols=50><? echo htmlentities($test);
> ?></textarea>
(you could also probably use CDATA sections and avoid calling
htmlentities(). i haven't tried it, and am skeptical that the various
browsers all get that right. i've never had a problem using
htmlentities() in this manner.)
jim