note 84784 added to function.strip-tags
| From: | Nexsja at osu1 dot php dot net | Date: | Wed, 30 Jul 2008 09:10:24 +0000 |
| Subject: | note 84784 added to function.strip-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-142916@lists.php.net to get a copy of this message | ||
Didn't find anything here so tried to write something of my own. I needed a strip_tags function
that would also trip all the html events from the allowed tags, so wrote a small function:
<?php
function mighty_strip_tags($string, $allowed_tags = '') {
return
preg_replace('/\<([a-z]+)\s[a-z=\'"<>:();\s]+\>(.*)<\/\1\>/i',
'<\\1>\\2</\\1>', strip_tags($string, $allowed_tags));
}
$str = '<b onclick="alert(\'lol\')" style="cursor:
pointer">loltext</b> <p>text</p><span
somecrap="fcra">moar</span>';
print mighty_strip_tags($str, '<b><p>');
//Outputs <b>loltext</b> <p>text</p>moar
?>
----
Server IP: 81.94.227.69
Probable Submitter: 159.148.10.188
----
Manual Page -- http://www.php.net/manual/en/function.strip-tags.php
Edit -- https://master.php.net/note/edit/84784
Del: integrated -- https://master.php.net/note/delete/84784/integrated
Del: useless -- https://master.php.net/note/delete/84784/useless
Del: bad code -- https://master.php.net/note/delete/84784/bad+code
Del: spam -- https://master.php.net/note/delete/84784/spam
Del: non-english -- https://master.php.net/note/delete/84784/non-english
Del: in docs -- https://master.php.net/note/delete/84784/in+docs
Del: other reasons-- https://master.php.net/note/delete/84784
Reject -- https://master.php.net/note/reject/84784
Search -- https://master.php.net/manage/user-notes.php