You have just tried to get elements by tagname. What you need to do is:-
1.Get all the elements by TagName.
2. Now take the classname from the tagname if exists.
3.Compare the classname wit ur input classname, if exists print that data.
Try out this , worked for me:-
$dom = new DOMDocument();
$dom->loadHTML($html);
$new_data = $dom->getElementsByTagName('*');
$matched = array();
//echo $data->nodeValue;
for ($i = 0; $i < $new_data->length; $i++) {
if (isset($new_data->item($i)->attributes->getNamedItem('class')->nodeValue)) {
$classname = $new_data->item($i)->attributes->getNamedItem('class')->nodeValue;
if ($classname == $identifier) {
$matched[] = $new_data->item($i)->nodeValue;
}
}
}
print_r($matched);