What are best practices for handling line breaks when outputting text from a file to a textarea in PHP?

When outputting text from a file to a textarea in PHP, it is important to handle line breaks properly to maintain the formatting of the text. One common approach is to use the PHP `nl2br()` function to convert newline characters into HTML line breaks (`<br>` tags) before displaying the text in the textarea.

&lt;?php
$file = &#039;example.txt&#039;;
$text = file_get_contents($file);
$formatted_text = nl2br($text);
?&gt;

&lt;textarea&gt;&lt;?php echo $formatted_text; ?&gt;&lt;/textarea&gt;