What is the common issue with line breaks (\n) in PHP when retrieving data from a text field in a database?

When retrieving data from a text field in a database in PHP, the line breaks (\n) may not be displayed correctly when outputting the text. This is because HTML does not recognize \n as a line break, so the text appears as a single line. To solve this issue, you can use the PHP function nl2br() to convert the line breaks to HTML <br> tags, which will properly display the text with line breaks in the browser.

// Retrieve data from the database
$text = $row[&#039;text&#039;];

// Convert line breaks to HTML &lt;br&gt; tags
$text_with_line_breaks = nl2br($text);

// Output the text with line breaks
echo $text_with_line_breaks;