Are there any best practices for handling line breaks in PHP when outputting text into a textarea field?

When outputting text into a textarea field in PHP, it's important to handle line breaks properly to ensure the formatting is maintained. One common approach is to use the PHP function nl2br() to convert newline characters into HTML line breaks (<br>). This function will preserve the line breaks when displaying the text in the textarea field.

// Assuming $text contains the text to be outputted in the textarea field
$text = &quot;This is a sample text with\nline breaks.&quot;;
echo nl2br($text);