How can the nl2br() function in PHP be used to properly handle line breaks in text output?
When outputting text in PHP, line breaks entered by the user may not be displayed correctly in HTML. This can result in all the text being displayed on a single line. To properly handle line breaks in text output, the nl2br() function can be used. This function converts newline characters (\n) into HTML line breaks (<br>) so that the text is displayed with proper line breaks in the browser.
$text = "This is a text with\nline breaks.";
echo nl2br($text);