W3docs

Converting <br> into a new line for use in a text area

In PHP, you can use the nl2br() function to convert line breaks (\n or \r\n) to <br> tags.

In PHP, you can use the nl2br() function to convert line breaks (\n or \r\n) to <br /> tags. To convert <br /> tags back to line breaks in a text area, you can use the str_replace() function.

Here is an example:

Example of converting <br /> into a new line to use in a text area in PHP

<?php

$text = "Line 1<br />Line 2<br />Line 3";
$text = str_replace("<br />", "\n", $text);

echo $text;

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

This will replace all instances of <br /> with a new line character, so that the text can be displayed correctly in a text area.