This is the kind of problem that PHP's DOMDocument
class excels at. First load the XML string using loadHTML()
method, and then use an XPath expression to traverse the DOM tree:
$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$item_tags = $xpath->query('//tag2/item');
foreach ($item_tags as $tag) {
echo $tag->tagName, PHP_EOL; // example
}