What is the function of nl2br() in PHP and how can it be used in this context?
The nl2br() function in PHP is used to insert HTML line breaks (<br>) before all newlines in a string. This is useful when displaying text from a textarea input in HTML, as newlines are not automatically converted to line breaks. By using nl2br(), we can ensure that the text is displayed with proper line breaks in the HTML output.
<?php
$text = "This is a text with\nnew lines.";
echo nl2br($text);
?>
Related questions
-
PHP MySQL optimization
-
PHP DateTime class IntlDateFormatter class
-
PHP file directory