The nl2br
function inserts a HTML line break (<br/>) before all new line characters.
It does not replace the line breaks which means the \n breaks are left intact.
PHP nl2br() Function has the following syntax.
string nl2br ( string str )
str
is the string to convert.
PHP nl2br() Function returns the string with new line character being converted by <br>.
Convert new line character with <br>.
<?PHP
$mystr = "This is a test\nfrom java2s.com.";
$brstr = nl2br($mystr);
print $brstr;
?>
The code above generates the following result.