Re: <textarea>
| From: | David Robley | Date: | Mon, 21 Jan 2002 04:17:45 +0000 |
| Subject: | Re: <textarea> | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-81324@lists.php.net to get a copy of this message | ||
[posted and mailed]
jtjohnston@courrier.usherb.ca (Jtjohnston) wrote in
news:3C48C142.8B4778BA@courrier.usherb.ca:
> This is the input of a <textarea>. I don't suppose there is an easier
> way of doing this?
>
> $mydata->KW = str_replace("\r", "", $mydata->KW);
> $mydata->KW = str_replace("\n", "<br>", $mydata->KW);
> $mydata->KW = str_replace("<br><br>", "<p>",
> $mydata->KW);
>
> What does htmlspecialchars do exactly?
> Yes I've read the docs, but didn't really follow.
>
> An email post & reply would be real helpful :)
> John
>
Why not use nl2br() to modify the end of line characters? And there is
probably no value, apart from saving characters in your source, to
translate a pair of <BR> to <P>. In fact, it might have unexpected effects
if you hapen to display the output inside of a closed <P> block. So,
$mydata->KW = nl2br($mydata->KW);
Depending on how this data is being used, you might prefer to do the
translation before display rather than storing html in your database. For
instance, if the data is to be edited, embedded html may be confusing,
depending on the level of knowledge of the person editing.
In respect of htmlspecialchars, recall that symbols like < and> have
special functions in html - they signal the start and end of html tags. So
if you actually want to use a < or > in your text, you should use the
special symbol > (note the special use of the ampersand here!)
htmlspecialchars will perform the translations for you.
--
David Robley
Temporary Kiwi