I'm printing a value of a mysql field on a contenteditable div
and I need it to adopt the structure corresponding to it. With the same divs
and line breaks br
.
I have tried the nl2br
function of php
but it only generates line breaks br
, so it does not work well for me. I need the complete structure.
For example:
<div id="textbox" contenteditable="true"><?php echo nl2br($text); ?></div>
Where $text
is a text with line breaks
from database.
So when executing nl2br
, change them all by br
.
I currently get this:
<div id="textbox" contenteditable="true">
Line 1
<br>
Line 2
<br>
<br>
Line 3
</div>
And I need to get this:
<div id="textbox" contenteditable="true">
Line 1
<div>Line 2</div>
<div>
<br>
</div>
<div>Line 3</div>
</div>
Which is what is generated automatically when writing on a contenteditable div
.