We often use textarea to insert multiple lines of data into database. While writing content to textarea we use line breaks. At the time of display if we simply echo text area content then it does not preserve line breaks and stick all of the data together.
There are two ways we can preserve line breaks mysql data -
1. Use nl2br() function
Returns string with ‘<br />’ or ‘<br>’ inserted before all newlines.
Example
<div> <div><code> <?php echo nl2br($row["myarea"]); ?> </code></div> </div>
2. Use <pre>textarea contents</pre> tag for display data. Put your textarea database contents inside this tag and it preserves line breaks in formatted text style.
Example
<?php echo "<pre>".$row["myarea"]."</pre>"; ?>
You can use any method alternatively. Output from both methods shows difference clearly in screenshot.


August 28th, 2011 at 10:10 am
Thanks a lot.
I am very very thankful to you.
Regards,
Sandeep