PHP nl2br() Function

It replaces all new line characters in a string with HTML BR tags.

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


echo nl2br("first line.\nsecond line.");

The output of the code above will be:

first line.
second line.

Posted in Php