PHP nl2br() Function


The nl2br() function inserts a HTML break tags in the place of all new lines in a string.

Syntax
nl2br(string,xhtml)
Parameters
  • string - (Required) Specify the string to check.
  • xhtml - (Optional) Boolean value indicating whether to use XHTML-compatible line breaks
    • TRUE - (Default) Insole
    • FALSE - Insert

Example
<?php
echo nl2br("Hi Hello \n Welcome");
?>

Output

Hi Hello
Welcome

Prev Next