note 81629 added to function.strip-tags
| From: | bohwaz+php at bohwaz dot net | Date: | Fri, 07 Mar 2008 04:19:34 +0000 |
| Subject: | note 81629 added to function.strip-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136808@lists.php.net to get a copy of this message | ||
Here's a 2 line regexp which will delete tags you haven't allowed :
<?php
// Allowed tags (regex)
$tags = 'b|i|em|strong|li|ul|ol|p|a|img|span|br|h[1-6]|pre|code';
$str =
preg_replace('§<+?((?!/?('.$tags.')(\s+.*|\s*)/?>).*)>+?§sU',
'', $str);
?>
All non-allowed tags are deleted. You can try with <script>, <<script>>, <
script >, <a href="<script>">, etc etc.
Note that it transforms things like <a
href="<script>alert(5);</script>"> in <a href="alert(5);">.
----
Server IP: 195.221.21.36
Probable Submitter: 82.225.170.198
----
Manual Page -- http://www.php.net/manual/en/function.strip-tags.php
Edit -- https://master.php.net/note/edit/81629
Del: integrated -- https://master.php.net/note/delete/81629/integrated
Del: useless -- https://master.php.net/note/delete/81629/useless
Del: bad code -- https://master.php.net/note/delete/81629/bad+code
Del: spam -- https://master.php.net/note/delete/81629/spam
Del: non-english -- https://master.php.net/note/delete/81629/non-english
Del: in docs -- https://master.php.net/note/delete/81629/in+docs
Del: other reasons-- https://master.php.net/note/delete/81629
Reject -- https://master.php.net/note/reject/81629
Search -- https://master.php.net/manage/user-notes.php