How can you automatically insert line breaks when copying multi-line text into a textarea in PHP?

When copying multi-line text into a textarea in PHP, line breaks may not be automatically inserted, resulting in a single line of text. To automatically insert line breaks, you can use the PHP function nl2br() to convert newlines to HTML line breaks <br>. This will display the multi-line text with appropriate line breaks in the textarea.

&lt;?php
// Assuming $multiLineText contains the multi-line text
$multiLineText = &quot;Line 1\nLine 2\nLine 3&quot;;
$multiLineTextWithBreaks = nl2br($multiLineText);
?&gt;
&lt;textarea&gt;&lt;?php echo $multiLineTextWithBreaks; ?&gt;&lt;/textarea&gt;