PHP: nl2br() function
Description
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
PHP: Tips of the Day
Deep flattens an array
Example:
<?php function tips_deepFlatten($items) { $result = []; foreach ($items as $item) { if (!is_array($item)) { $result[] = $item; } else { array_push($result, ...tips_deepFlatten($item)); } } return $result; } Print_r(tips_deepFlatten([1, [2], [[3], 4], 5])); ?>
Output:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework