note 96483 added to function.strip-tags

From: Date: Mon, 01 Mar 2010 15:07:40 +0000
Subject: note 96483 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-166471@lists.php.net to get a copy of this message
Here is support for stripping content for the reverse strip_tags function: function strip_only($str, $tags, $stripContent = '') { 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) $stripContent = '(.+</'.$tag.'[^>]*>|)'; $str = preg_replace('#</?'.$tag.'[^>]*>'.$stripContent.'#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. Does anyone know how to support it? ---- Server IP: 212.150.176.151 Probable Submitter: 109.64.199.46 ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/96483 Del: integrated -- https://master.php.net/note/delete/96483/integrated Del: useless -- https://master.php.net/note/delete/96483/useless Del: bad code -- https://master.php.net/note/delete/96483/bad+code Del: spam -- https://master.php.net/note/delete/96483/spam Del: non-english -- https://master.php.net/note/delete/96483/non-english Del: in docs -- https://master.php.net/note/delete/96483/in+docs Del: other reasons-- https://master.php.net/note/delete/96483 Reject -- https://master.php.net/note/reject/96483 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166471) next »