The data entered into the textarea in a html form contains lines break as n , however when we have to save and display the same data back as html and maintain the formatting, these line feed n needs to be converted into html </br> elements.

The following snippet shows the same:

  1. $text_with_breaks=nl2br($_POST['text']);
  2. echo $text_with_breaks;

nl2br() is a function which inserts a
automatically at the end of every line.