nl2br

Inserts HTML line breaks before all newlines in a string

Syntax

nl2br ( string $string [, bool $is_xhtml = TRUE ] ) : string

Parameters

string

The input string.

is_xhtml

Whether to use XHTML compatible line breaks or not.

Return

Returns the altered string.

Examples

string

<?

$string = "XHTML\ndocument\n";

$return = nl2br($string);
echo $return;

?>
XHTML<br />
document<br />

is_xhtml

<?

$string = "HTML\ndocument\n";
$is_xhtml = false;

$return = nl2br($string, $is_xhtml);
echo $return;

?>
HTML<br>
document<br>

Newlines

<?

$string = "n\n" . "nr\n\r" . "r\r" . "rn\r\n" . "PHP_EOL" . PHP_EOL;

$return = nl2br($string);
echo $return;

?>
n<br />
nr<br />

r<br />
rn<br />
PHP_EOL<br />

PHP

Home Menu