Search code snippets, questions, articles...

nl2br() function in PHP

   echo nl2br("First line.\nSecond line.\nThird Line");
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
First line
Second line
Third line

To replace newline \n with <br>, we use nl2br function in PHP. This will generate Html with <br> tags and will allow showing the content in newline when required.

Was this helpful?