note 76045 deleted from function.strip-tags by danbrown

From: Date: Fri, 23 Sep 2011 16:04:19 +0000
Subject: note 76045 deleted from function.strip-tags by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183381@lists.php.net to get a copy of this message
Note Submitter: Matthieu Larcher ---- I noticed some problems with the strip_selected_tags() function below, sometimes big chunks of contents where suppressed... Here is a modified version that should run better. <?php function strip_selected_tags($text, $tags = array()) { $args = func_get_args(); $text = array_shift($args); $tags = func_num_args() > 2 ? array_diff($args,array($text)) : (array)$tags; foreach ($tags as $tag){ while(preg_match('/<'.$tag.'(|\W[^>]*)>(.*)<\/'. $tag .'>/iusU', $text, $found)){ $text = str_replace($found[0],$found[2],$text); } } return preg_replace('/(<('.join('|',$tags).')(|\W.*)\/>)/iusU', '', $text); } ?>

« previous php.notes (#183381) next »