How can PHP developers address the issue of \n characters being converted to new lines when outputting data from a database in a <textarea>?

When outputting data from a database in a <textarea> using PHP, the issue of \n characters being converted to new lines can be addressed by using the nl2br() function to convert the new lines to <br> tags. This will maintain the formatting of the text within the <textarea> element.

&lt;textarea&gt;&lt;?php echo nl2br($data_from_database); ?&gt;&lt;/textarea&gt;