Código PHP:
function closetags($text,$tag) {
$return = $text;
@$tags = explode(",",$tag);
for ($a=0;$a<count($tags);$a++) {
$tag = "<".$tags[$a].">";
@$texts = explode($tag,$text);
if (count($texts) > 1) {
$last = count($texts)-1;
if (@count(explode($tag,$texts[$last])) > 1) {
$return .= str_replace("<","</",$tag);
}
}
}
return $return;
}