如果字符串使用HTML标记格式正确,如何获取

I want to verify if a string is correctly formatted with HTML Tags. For example:

    "<b>This Is wrong"

This Is the function I used.

function closetags($html) { 

 preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result); $openedtags = $result[1];

   preg_match_all('#</(([a-z])+)>#iU', $html, $result); $closedtags = $result[1]; $len_opened = count($openedtags); 

   if (count($closedtags) == $len_opened) { return true; } else { return false;}
}

I've already tried to use this but when the string Is:

"<B>This is correct</>"

It doesn't work..

Thank you in advance Francesco