note 71402 deleted from function.strip-tags by danbrown

From: Date: Fri, 23 Sep 2011 16:04:30 +0000
Subject: note 71402 deleted from function.strip-tags by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183383@lists.php.net to get a copy of this message
Note Submitter: bermi ferrer ---- Here is a faster and tested version of strip_selected_tags. Previous example had a small bug that has been fixed now. <?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){ if( preg_match_all( '/<'.$tag.'[^>]*>([^<]*)<\/'.$tag.'>/iu', $text, $found) ){ $text = str_replace($found[0],$found[1],$text); } } return preg_replace( '/(<('.join('|',$tags).')(\\n|\\r|.)*\/>)/iu', '', $text); } ?>

« previous php.notes (#183383) next »