Luis
Luis

Reputation: 235

Displaying HTML in a textarea once it has been formatted

I've used a script to transform line breaks into <li> tags in a textarea using PHP, I now want to be able to output the stored content (in <li> ) tags not formatted. So it would just appear as if you'd written it originally.

I'm echoing the row into the textarea but naturally it outputs the HTML as well.

Does anyone know of a function or method to strip the tags and replace them with the originally defined line breaks?

Thank you in advance.

Answer: Do not format text before storing it in the database, keep it in it's original form (but do check for dodgy characters etc) and convert it to HTML upon display.

Upvotes: 0

Views: 1083

Answers (2)

Your Common Sense
Your Common Sense

Reputation: 158007

Do not do it that way.
Do not transform linebreaks to tags before storing your data but convert it right before printing it onto HTML page.
That's usual way of doing such things.

Upvotes: 1

trickwallett
trickwallett

Reputation: 2468

nl2br() is the ootb method for converting newlines to <br>'s

http://php.net/manual/en/function.nl2br.php

Upvotes: 0

Related Questions