Changing a New Line to a Break

Posted by: twmeier

Tagged in: PHP

There is a great php function takes a variable and changes the  new lines (\n) into breaks (<br/>).

For example, a user submits a form on your website and used a textarea to submit a couple of paragraphs. You then retrieve this data from the database and echo it out in html. You will notice that it is now just one big paragraph.

To fix this problem, you the function: nl2br

Here is how you might use this:

<?php
     $paragraphs = nl2br($paragraphs);
     echo $paragraphs;
?>