When a user save a text from a textarea:
bfajsdb fkjasdfasjkdfasdfasdf asdf asdf sdf
asdfasdfasdfasdf asd asdf asdf
sdfasdfasdf
from a textarea using nl2br_except_pre function in codeignter it saves it in the database like :
bfajsdb fkjasdfasjkdfasdfasdf asdf asdf sdf
<br>
asdfasdfasdfasdf asd asdf asdf
<br>
sdfasdfasdf
It is nice for output in div or p tags. or in html output in general.
However, when repoopulating inside textarea again it shows the
tags, which is ugly and confuse the user.
How can I sanitize the output before repopulating the saved value from database so it looks in the textarea like this:
bfajsdb fkjasdfasjkdfasdfasdf asdf asdf sdf
asdfasdfasdfasdf asd asdf asdf
sdfasdfasdf
and not like this:
bfajsdb fkjasdfasjkdfasdfasdf asdf asdf sdf
<br>
asdfasdfasdfasdf asd asdf asdf
<br>
sdfasdfasdf
Well, the crude answer will be ‘just use strip_tags‘:
But, in fact, there’s much more to that: perhaps you need to worry about sanitizing your output, not just cleaning out irrelevant tags. I suggest reading this discussion on that topic.