<?php
function strip_only($str, $tags) {
if(!is_array($tags)) {
$tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
if(end($tags) == '') array_pop($tags);
}
foreach($tags as $tag) $str = preg_replace('#</?'.$tag.'[^>]*>#is', '', $str);
return $str;
}
$str = '<p style="text-align:center">Paragraph</p><strong>Bold</strong><br/><span style="color:red">Red</span><h1>Header</h1>';
echo strip_only($str, array('p', 'h1'));
echo strip_only($str, '<p><h1>');
?>
Output:
Paragraph<strong>Bold</strong><br/><span style="color:red">Red</span>Header
No comments:
Post a Comment