note 98007 deleted from function.strip-tags by danbrown

From: Date: Thu, 20 May 2010 15:46:25 +0000
Subject: note 98007 deleted from function.strip-tags by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169458@lists.php.net to get a copy of this message
Note Submitter: sly at noiretblanc dot org ---- One bug in LWC's strip_tags function: You must add a U option in the preg_replace to have it work when stripping content : $str = 'test : <tag>blah</tag> hello <tag>blah</tag>'; $b = strip_only($str, 'tag', true); will return "test : " without the U option and return "test : hello" with it. function strip_only($str, $tags, $stripContent = false) { $content = ''; if(!is_array($tags)) { $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags)); if(end($tags) == '') array_pop($tags); } if ($stripContent) foreach($tags as $tag) $str = preg_replace('#<'.$tag.'[^>]*>.+</'.$tag.'[^>]*>'.'#isU', '', $str); else foreach($tags as $tag) $str = preg_replace('#'.'</?'.$tag.'[^>]*>'.'#is', '', $str); return $str; }

« previous php.notes (#169458) next »