Re: need help with line breaks
| From: | Brian Clark | Date: | Sat, 11 Nov 2000 08:44:19 +0000 |
| Subject: | Re: need help with line breaks | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24767@lists.php.net to get a copy of this message | ||
Siim Einfeldt aka Itpunk wrote:
When I write something to a form textarea and then to the database, it doesn`t leave any marks of linebreaks at all, so all comes out like one big text without any breaks.Are you sure? Remember, if you're using something like phpMyAdmin to view the contents of a table via browser, you won't see any line breaks (\n) because HTML could care less about tabs and newlines.
Now, if I use nl2br, then breaks are there where they are supposed to be, but when i want to change the text, then I see these annoying <BR>-s inside the text. How to change it?The solution is to only use nl2br() when you want to actually display the data as HTML. Don't pass the data through nl2br() before you insert it into the database; pass it through nl2br() right before you display it on the page as HTML. Then, when you want to edit the data with a form, it'll appear normal. -Brian