note 96495 added to function.strip-tags

From: Date: Tue, 02 Mar 2010 12:04:28 +0000
Subject: note 96495 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-166524@lists.php.net to get a copy of this message
Oops, here are some fixes for the support for stripping content for the reverse strip_tags function: <?php 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); } foreach($tags as $tag) { if ($stripContent) $content = '(.+</'.$tag.'[^>]*>|)'; $str = preg_replace('#</?'.$tag.'[^>]*>'.$content.'#is', '', $str); } return $str; } $str = '<font color="red">red</font> text'; $tags = 'font'; $a = strip_only($str, $tags); // red text $b = strip_only($str, $tags, true); // text ?> Note this function always assumed no two tags start the same way (e.g. <bla> and <blas>) and therefore censors blas along with bla. ---- Server IP: 69.147.83.197 Probable Submitter: 109.64.200.164 ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/96495 Del: integrated -- https://master.php.net/note/delete/96495/integrated Del: useless -- https://master.php.net/note/delete/96495/useless Del: bad code -- https://master.php.net/note/delete/96495/bad+code Del: spam -- https://master.php.net/note/delete/96495/spam Del: non-english -- https://master.php.net/note/delete/96495/non-english Del: in docs -- https://master.php.net/note/delete/96495/in+docs Del: other reasons-- https://master.php.net/note/delete/96495 Reject -- https://master.php.net/note/reject/96495 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166524) next »