note 98007 added to function.strip-tags

From: Date: Thu, 20 May 2010 12:12:23 +0000
Subject: note 98007 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-169445@lists.php.net to get a copy of this message
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; } ---- Server IP: 89.31.146.176 Probable Submitter: 88.180.118.222 ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/98007 Del: integrated -- https://master.php.net/note/delete/98007/integrated Del: useless -- https://master.php.net/note/delete/98007/useless Del: bad code -- https://master.php.net/note/delete/98007/bad+code Del: spam -- https://master.php.net/note/delete/98007/spam Del: non-english -- https://master.php.net/note/delete/98007/non-english Del: in docs -- https://master.php.net/note/delete/98007/in+docs Del: other reasons-- https://master.php.net/note/delete/98007 Reject -- https://master.php.net/note/reject/98007 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169445) next »