# Enter the tags to check for. Can only handle tags with
# no attributes at the moment
@tags = qw(b i u);
# Put it in some HTML
$html = "HelloHello"; # i.e. no and tag
# Iterate through each tag
foreach $tag (@tags) {
# If $html contains that tag
while (($html =~ /<$tag>/i) or ($html =~ /<\/$tag>/i)) {
# If it contains the opening tag, keep count
# of many opening tags there are.
if ($html =~ /<$tag>/i) {
$opening++;
}
# If it contains the closing tag, keep count
# of many closing tags there are.
if ($html =~ /<\/$tag>/i) {
$closing++;
}
# Remove the tags for the next iteration
$html =~ s/<$tag>//si;
$html =~ s/<\/$tag>//si;
}
# If the number of opening tags and closing tags
# don't match, then something is wrong
if ($opening != $closing) {
if ($opening > $closing) {
# More opening than closing, therefore
# missing closing
print "Warning, missing $tag> tag\n";
} else {
print "Warning, missing <$tag> tag\n";
}
}
# Prepare for next iteration
$opening = $closing = undef;
}