How to keep the carriage return in textarea using PHP?


I’ve created submission forms with the textarea box, but when I echoed out the submission, all the carriage returns disappeared! Of course you don’t want to force the user to type <br /> or <p> tags into the posts. Actually, I learned that the carriage returns did not disappear, you simply need to add a bit of code to when you output the content. By using nl2br all the carriage returns appear again~!

 

PHP Code:

$data = mysql_query('SELECT text FROM table');
while ($row = mysql_fetch_assoc($data))
{
   echo "<p>".nl2br($row['text'])."</p>n";
,

Leave a Reply

Your email address will not be published. Required fields are marked *