How PHP nl2br() Function Works?

nl2br() function will replace \n into newline. so let’s see syntax and example.

Description

nl2br(string $string, bool $use_xhtml = true): string

Returns string with <br /> or <br> inserted before all newlines (\r\n\n\r\n and \r).

Parameters
string

The input string.

use_xhtml

Whether to use XHTML compatible line breaks or not.

Examples

<?php
echo nl2br("One line.\nAnother line.");
?>

Result

One line.
Another line.
Please follow and like us:

Related Posts

Leave a Reply

Share