PHP.nl

nl2br

nl2br

Inserts HTML line breaks before all newlines in a string

string **nl2br** string $string bool $use_xhtml

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

stringThe input string.

use_xhtmlWhether to use XHTML compatible line breaks or not.

Returns the altered string.

**Voorbeeld: Using **

<?php
echo nl2br("foo isn't\n bar");
?>
foo isn't<br />
 bar

Voorbeeld: Generating valid HTML markup using the parameter

<?php
echo nl2br("Welcome\r\nThis is my HTML document", false);
?>
Welcome<br>
This is my HTML document

Voorbeeld: Various newline separators

<?php
$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
?>
This<br />
is<br />
a<br />
string<br />

htmlspecialchars``htmlentities``wordwrap``str_replace