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 na开发者_如何学Pythonturally 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.
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.
nl2br()
is the ootb method for converting newlines to <br>'s
http://php.net/manual/en/function.nl2br.php
精彩评论