note 90660 added to function.preg-match
| From: | daniel dot chcouri at gmail dot com | Date: | Sun, 03 May 2009 13:09:03 +0000 |
| Subject: | note 90660 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-154157@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'));
?>
----
Server IP: 82.80.248.162
Probable Submitter: 217.132.132.64
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master.php.net/note/edit/90660
Del: integrated -- https://master.php.net/note/delete/90660/integrated
Del: useless -- https://master.php.net/note/delete/90660/useless
Del: bad code -- https://master.php.net/note/delete/90660/bad+code
Del: spam -- https://master.php.net/note/delete/90660/spam
Del: non-english -- https://master.php.net/note/delete/90660/non-english
Del: in docs -- https://master.php.net/note/delete/90660/in+docs
Del: other reasons-- https://master.php.net/note/delete/90660
Reject -- https://master.php.net/note/reject/90660
Search -- https://master.php.net/manage/user-notes.php