note 90660 deleted from function.preg-match by cmb

From: Date: Sun, 13 Oct 2019 07:53:35 +0000
Subject: note 90660 deleted from function.preg-match by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212616@lists.php.net to get a copy of this message
Note Submitter: daniel dot chcouri at gmail dot com ---- Html tags delete using regular expression <?php function removeHtmlTagsWithExceptions($html, $exceptions = null){ if(is_array($exceptions) && !empty($exceptions)) { foreach($exceptions as $exception) { $openTagPattern = '/<(' . $exception . ')(\s.*?)?>/msi'; $closeTagPattern = '/<\/(' . $exception . ')>/msi'; $html = preg_replace( array($openTagPattern, $closeTagPattern), array('||l|\1\2|r||', '||l|/\1|r||'), $html ); } } $html = preg_replace('/<.*?>/msi', '', $html); if(is_array($exceptions)) { $html = str_replace('||l|', '<', $html); $html = str_replace('|r||', '>', $html); } return $html; } // example: print removeHtmlTagsWithExceptions(<<<EOF <h1>Whatsup?!</h1> Enjoy <span style="text-color:blue;">that</span> script<br /> <br /> EOF , array('br')); ?>

« previous php.notes (#212616) next »