note 90660 modified in function.preg-match by danbrown

From: Date: Sun, 03 May 2009 17:01:04 +0000
Subject: note 90660 modified in function.preg-match by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154162@lists.php.net to get a copy of this message
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')); ?> --was-- 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')); ?> http://php.net/manual/en/function.preg-match.php

« previous php.notes (#154162) next »