What are the best practices for transferring line breaks from HTML textarea to PHP?

When transferring text with line breaks from an HTML textarea to PHP, the line breaks are represented by "\n" characters in the PHP code. To properly handle these line breaks, you can use the PHP function nl2br() to convert the "\n" characters to HTML <br> tags for display on a webpage.

// Retrieve text from HTML textarea
$text = $_POST[&#039;textarea&#039;];

// Replace &quot;\n&quot; characters with HTML &lt;br&gt; tags
$text_with_line_breaks = nl2br($text);

// Display text with line breaks
echo $text_with_line_breaks;