nl2br() in php

The nl2br() function takes a string as a parameter and replaces all the newlines in it with the HTML tag. This capability is useful for echoing a long string to the browser

Example

<p>Your feedback (shown below) has been sent.</p>
<p><?php echo nl2br(htmlspecialchars($feedback)); ?> </p>

Remember that HTML disregards plain whitespace, so if you don’t filter this output through nl2br(), it will appear on a single line (except for newlines forced by the browser window)

Leave a Comment