public static function removeInnerTags(string $html, string $tag) : string
{
if (preg_match_all('~(?:<' . $tag . '>)|(?:</' . $tag . '>)|(?:<[^>]+>)|(?:[^<]+)~i', $html, $matches)) {
$html = '';
$level = 0;
foreach ($matches[0] as $htmlPart) {
if (0 === stripos($htmlPart, '<' . $tag)) {
$level++;
if (1 === $level) {
$html .= $htmlPart;
}
} elseif (0 === stripos($htmlPart, '</' . $tag)) {
if (1 === $level) {
$html .= $htmlPart;
}
$level--;
} else {
$html .= $htmlPart;
}
}
}
return $html;
}