public static function removeTags(string $html, array $tags = []) : string
{
// Default set of tags
static $default = ['frameset', 'frame', 'noframes', 'iframe', 'script', 'noscript', 'style', 'link', 'object', 'embed', 'form', 'input', 'select', 'textarea', 'button'];
// If no tags are set, the default set will be used
if (empty($tags)) {
$tags = $default;
}
// Remove given tags
foreach ($tags as $tag) {
switch ($tag) {
// Embed
case 'embed':
// Second variant is because of Tidy that processes <embed> this way
$pattern = ['~\\s*<embed[^>]*>.*?</embed>~is', '~\\s*<embed[^>]*>~is'];
break;
// Self closing tags
// Self closing tags
case 'link':
case 'meta':
case 'br':
case 'hr':
case 'img':
case 'input':
$pattern = ['~\\s*<' . $tag . '[^>]*>~is'];
break;
// Pair tags
// Pair tags
default:
$pattern = ['~\\s*<' . $tag . '(?:\\s+[^>]*)?>.*?</' . $tag . '>~is'];
break;
}
$html = preg_replace($pattern, '', $html);
}
return $html;
}