How can PHP handle "Enter" line breaks from an HTML textarea input?

When a user enters text into an HTML textarea and presses "Enter", the input is submitted with line breaks represented by "\n". To handle these line breaks in PHP, you can use the nl2br() function to convert the "\n" characters into HTML <br> tags, which will display the text with line breaks in the browser.

// Get the textarea input from the form
$text = $_POST[&#039;textarea_input&#039;];

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

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