nl2br
Insert HTML newline tag before all new lines of a string
nl2br()
function inserts HTML newlines (<br> or <br />) before each new line in the string (\n).
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
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
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:
|