substituting br with \n with nl2br

The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.

Example

<!DOCTYPE html>
<html>
<body>

<?php
echo nl2br("First line.\nSecond line.");
?>

</body>
</html>

Output

First line.
Second line.