How can PHP be used to handle line breaks in <textarea> input?

When handling input from a <textarea> in PHP, line breaks are represented by the newline character (\n). To properly handle line breaks in <textarea> input, you can use the nl2br() function in PHP. This function converts newlines (\n) into HTML line breaks (<br>) so that the text is displayed correctly when outputted on a webpage.

&lt;?php
// Retrieve the input from the &lt;textarea&gt;
$text = $_POST[&#039;textarea_input&#039;];

// Convert newlines to HTML line breaks
$text_with_line_breaks = nl2br($text);

// Output the text with line breaks
echo $text_with_line_breaks;
?&gt;