note 8814 added to strip_tags
| From: | isbeam at usa dot net | Date: | Fri, 29 Sep 2000 04:54:26 +0000 |
| Subject: | note 8814 added to strip_tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-5576@lists.php.net to get a copy of this message | ||
A function to filter out anything except "nice" HTML; ie TITLE tags (nasty) are escaped,
while B tags are left alone. Doesn't try to validate though (make sure tages are closed/nested)
function escapeBadHTML($str) {
$allowed = "br|b|i|p|u|a";
$str = preg_replace("/< # match the open bracket
( # begin gathering
(?! # followed by anything except...
\/? # maybe a slash...
($allowed) # and one of the allowed chunks...
\b # and a word boundary.
) #
[^>]* # and any of not-">"'s
) # end gathering
> # followed by the >
/xis", "<\\1>", $str);
return $str;
}
http://www.php.net/manual/function.strip-tags.php