Is it possible to use nl2br() to automatically insert line breaks in text retrieved from a textarea input field in PHP?

Yes, it is possible to use nl2br() to automatically insert line breaks in text retrieved from a textarea input field in PHP. To achieve this, you can retrieve the text from the textarea input field using $_POST, apply nl2br() function to the text, and then display it on the webpage. This will convert newline characters in the text to <br> tags, preserving the line breaks entered by the user.

&lt;?php
if ($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;) {
    $text = $_POST[&#039;textarea_input&#039;];
    $formatted_text = nl2br($text);
    echo $formatted_text;
}
?&gt;

&lt;form method=&quot;post&quot; action=&quot;&lt;?php echo $_SERVER[&#039;PHP_SELF&#039;]; ?&gt;&quot;&gt;
    &lt;textarea name=&quot;textarea_input&quot;&gt;&lt;/textarea&gt;
    &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;
&lt;/form&gt;