faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

17 of 25 people (68%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Without using <pre>, how do I get textarea to save format of entered text into MySQL field?

Feb 24th, 2008 19:52
dman, Praveen Kumar Kukkapalli, Michael Wales, Simon --, http://www.ttnr.org


Actually when you enter newlines in the text area it will store as you
have entered but while retrieving and showing in teh HTML it will show
properly if you use nl2br() function. If you wanted to show in the text
area itself then you need not to do anything, it will just show the same
way as you entered.
You can use the nl2br function to convert hard returns in the textarea 
to <br>, so when it's echoed it will use the new lines.
If you'd like some indenting on each new paragraph then I would do 
something like this:
<?
  $textblock = nl2br($textblock);
  $textblock = "   " . $textarea;
  $textblock = ereg_replace("<br>", "<br>   ", 
$textblock);
?>
I'm pretty sure all of that's right, but you get the idea.