note 28723 added to function.nl2br
| From: | jotkailay at NOSPAM dot hotmail dot com | Date: | Wed, 22 Jan 2003 13:01:34 +0000 |
| Subject: | note 28723 added to function.nl2br | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42584@lists.php.net to get a copy of this message | ||
Hello,
I got stuck on this one for a while. If you want to store the data entered
as is in the database, but then read it in as a javascript variable so it can be displayed
optionally in a textarea (for example, I have a text area that changes its info depending on which
show option is clicked) then you need to do this :
Say you get comments fro the database :
$comments = $row{'comments'};
Then to make it available to javascript variable do :
$comments = str_replace("\r\n", "\\r\\n", $comments);
Now you can feed $comments as javascript information, otherwise
javascript sees \r\n as actual breaks in the string, and you cannot have a multiple line javascript
variable. nl2br won't work since a textarea will not parse out the br as breaklines.
Thanks for all the help elsewhere on this amazing site,
Jot
--
http://www.php.net/manual/en/function.nl2br.php
http://master.php.net/manage/user-notes.php?action=edit+28723
http://master.php.net/manage/user-notes.php?action=delete+28723
http://master.php.net/manage/user-notes.php?action=reject+28723