How can you add line breaks and new lines to text from a textarea in PHP?

When retrieving text from a textarea in PHP, line breaks are represented by the "\n" character. To display these line breaks as actual line breaks in HTML, you can use the nl2br() function in PHP. This function converts newline characters into <br> tags, which will display as line breaks in the browser.

$text = $_POST[&#039;textarea_input&#039;]; // Retrieve text from textarea
$text_with_line_breaks = nl2br($text); // Convert newline characters to &lt;br&gt; tags
echo $text_with_line_breaks; // Display text with line breaks