Reputation: 163
I need to display the text retrieved from the database in the <textarea>
tag. But the thing is that i get this text from db with html tags, like:
The line number 1<br>
The line number 2<br>
The line number three<br><br>
But when i do:
<textarea>mytext</textarea>
Inside the textarea box i get exatly the same text will all the tags, like
The line number 1<br>
The line number 2<br>
The line number three<br><br>
htmlspecialchars didn't help. It just made it to display entities instead of formatted text, without any tags as if it was show on the web page What I need is just to show formatted text without possibility to edit it. How can I accomplish this?
Upvotes: 0
Views: 1798
Reputation: 1109532
I'm not sure why you have HTML tags like <br>
in your database. Did you use nl2br
before saving or something? You shouldn't do that. Replace them by fullworthy newlines and it'll work in the textarea.
If you intend to present them in a non-textarea afterwards, then you're allowed to use nl2br
or like (only at the point of presentation!), or just use CSS white-space: pre
instead.
Upvotes: 0