J'ai testé cette fonction, elle fonctionne aussi pour les balises imbriquées, utilisez true/false pour exclure/inclure vos balises. Trouvé ici : https://www.php.net/manual/en/function.strip-tags.php
<?php
function strip_tags_content($text, $tags = '', $invert = FALSE) {
preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
$tags = array_unique($tags[1]);
if(is_array($tags) AND count($tags) > 0) {
if($invert == FALSE) {
return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
}
else {
return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
}
}
elseif($invert == FALSE) {
return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
}
return $text;
}
// Sample text:
$text = '<b>sample</b> text with <div>tags</div>';
// Result for:
echo strip_tags_content($text);
// text with
// Result for:
echo strip_tags_content($text, '<b>');
// <b>sample</b> text with
// Result for:
echo strip_tags_content($text, '<b>', TRUE);
// text with <div>tags</div>