note 81629 deleted from function.strip-tags by ezyang

From: Date: Fri, 07 Mar 2008 04:28:57 +0000
Subject: note 81629 deleted from function.strip-tags by ezyang
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-136810@lists.php.net to get a copy of this message
Note Submitter: bohwaz+php at bohwaz dot net Reason: bad code ---- 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);">.

« previous php.notes (#136810) next »