note 70862 deleted from function.strip-tags by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 15:58:30 +0000 |
| Subject: | note 70862 deleted from function.strip-tags by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154727@lists.php.net to get a copy of this message | ||
Note Submitter: anonymous
----
A different approach to cleaning up HTML would be to first escape all unsafe characters:
& to &
< to <
> to >
then to unescape matching pairs of tags back (e.g.
"<b>hello</b>" => "<b>hello</b>"), if
it is identified safe.
This backwards-approach should be safer because if a tag is not identified correctly, it is, at the
end, in an escaped state.
So if a user enters invalid html, or tags that are unsupported or unwanted, they are shown in plain
text, and not stripped away. This is good, because the characters "<" and
">" might have been used in a different way (e.g. to make a text arrow: "a
<=> b").
This is the case in most forums (apart from the fact that they use "[tag]"-tags instead of
"<tag>"-tags)