and a browser would build from the fragment. function parseItem($html) { $doc = new DOMDocument(); libxml_use_internal_errors(true); $doc->loadHTML(''); libxml_clear_errors(); $li = $doc->getElementsByTagName('li')->item(0); $a = $doc->getElementsByTagName('a')->item(0); $tags = array(); foreach ($doc->getElementsByTagName('*') as $el) $tags[$el->nodeName] = true; return array( 'id' => $li ? $li->getAttribute('id') : null, 'href' => $a ? $a->getAttribute('href') : null, 'class' => $a ? $a->getAttribute('class') : null, 'tags' => implode(',', array_keys($tags)), ); } function item($id, $href, $class = '') { return parseItem(buildMenuItem('x', $id, 'Label', $href, 'movie', $class, '', true)); } // A constant href, as most callers pass. $r = item('getEventsHTML', '?view=events'); check('plain href unchanged', $r['href'], '?view=events'); check('plain id unchanged', $r['id'], 'getEventsHTML'); // Raw values with markup stay inside their attributes. $r = item('i"> array('Query' => array('terms' => array( 'attr' => array('attr' => 'StartDateTime', 'op' => '>=', 'val' => 'x">'), 0 => array('attr' => 'StartDateTime', 'op' => '<=', 'val' => '2026-10-02 00:00:00'), )))); $r = parseItem(getMontageReviewHTML('console', true)); check('montage review sidebar: href', $r['href'], '?view=montagereview&fit=1&minTime='.urlencode('x">').'&maxTime='.urlencode('2026-10-02 00:00:00').'&live=0'); check('montage review sidebar: no injected elements', $r['tags'], 'html,body,ul,li,a,span,i'); echo "\n$passes passed, $failures failed\n"; exit($failures ? 1 : 0);