Current Location: Home> Function Categories> nl2br

nl2br

Insert HTML newline tag before all new lines of a string
Name:nl2br
Category:String
Programming Language:php
One-line Description:Insert HTML newlines before each new line in the string.

Definition and usage

nl2br() function inserts HTML newlines (<br> or <br />) before each new line in the string (\n).

Example

Example 1

Insert a newline before a new line (\n) in a string:

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

The browser output of the above code:

 One line.
Another line.

HTML input of the above code (see source code):

 One line.<br />
Another line.

Try it yourself

Example 2

By using the xhtml parameter, insert a newline before the new line (\n):

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

The browser output of the above code:

 One line.
Another line.

HTML input of the above code (see source code):

 One line.<br>
Another line.

Try it yourself

grammar

 nl2br ( string , xhtml )
parameter describe
string Required. Specifies the string to be checked.
xhtml

Optional. Boolean value indicating whether to use compatible XHTML line breaks:

  • TRUE- Default. Insert<br />
  • FALSE - Insert<br>
Similar Functions
Popular Articles