PHP: nl2br() function
PHP: Inserts HTML line breaks before all newlines in a string
The nl2br() function is used to insert HTML line breaks ('<br />') before all newlines (\n) in a string.
Version:
(PHP 4 and above)
Syntax:
nl2br(input_string)
Parameter:
Name | Description | Required / Optional |
Type |
---|---|---|---|
input_string | The input string | Required | String |
is_xhtml | Whether XHTML compatible line breaks will be used or not. | Optional | Boolean |
Return value:
Returns the altered string.
Value Type: String.
Pictorial Presentation
Example:
<?php
echo nl2br("w3resource \n. \ncom");
?>
Output:
w3resource . com
View the example in the browser
See also
Previous: metaphone
Next: number_format
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/php/function-reference/nl2br.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics