note 84784 modified in function.strip-tags by danbrown

From: Date: Wed, 30 Jul 2008 18:30:13 +0000
Subject: note 84784 modified in function.strip-tags by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142949@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 strip 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 ?> --was-- 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 ?> http://php.net/manual/en/function.strip-tags.php

« previous php.notes (#142949) next »