Insert a newline character before a new line (n) in a string:
<? php echo nl2br ( " One line.nAnother line. " ); ?>The browser output of the above code is as follows:
One line.Another line.The HTML input for the above code is as follows (view source code):
One line.<br />Another line.The nl2br() function inserts an HTML newline character (<br> or <br />) before each new line (n) in a string.
nl2br( string,xhtml )
parameter | describe |
---|---|
string | Required. Specifies the string to check. |
xhtml | Optional. A Boolean value indicating whether to use XHTML-compatible line breaks: TRUE - Default. Insert<br /> FALSE - insert<br> |
Return value: | Returns the converted string. |
---|---|
PHP version: | 4+ |
Update log: | Prior to PHP 4.0.5, this function was inserted<br>. As of PHP 4.0.5, this function inserts an XHTML-compatible<br />. In PHP 5.3, the xhtml parameter was added. |
Insert a newline character before a new line (n) by using the xhtml parameter:
<?php echo nl2br ( " One line. n Another line. " , false ) ; ?>The browser output of the above code is as follows:
One line.Another line.The HTML input for the above code is as follows (view source code):
One line.<br>Another line.