PHP » Strings » nl2br()

Syntax:
string nl2br(string text)
text
Text with new line characters.

Converts new line characters to html tags.

New line characters have no effect in a web browser. To get a line break, the <br> tag should be used. nl2br() converts all new line characters in a string to <br> tags.

Examples

Code:
<?php

$s = "This is \na text with \nline breaks";

print "$s<br><br>";
print nl2br($s);

?>
Output:
This is a text with line breaks

This is
a text with
line breaks
Explanation:

This code shows how nl2br can be used to give new line characters effect in a web browser.

See Also: