How can nl2br() be used to display line breaks from a database in PHP?
When retrieving text from a database in PHP, line breaks may be stored as '\n' characters. To display these line breaks properly in HTML, you can use the nl2br() function in PHP. This function converts newline characters to HTML line breaks (<br> tags), allowing the text to be displayed with proper line breaks on the webpage.
// Retrieve text from the database
$text = "Hello\nWorld";
// Use nl2br() to convert newline characters to HTML line breaks
$displayText = nl2br($text);
// Display the text with line breaks on the webpage
echo $displayText;