使用SimpleHTMLDOM获取class属性

I am trying to get the value of the attribute class using the following code

foreach($sub->children() as $child){
    if($child->class!=="viewAll"){
        echo $child->plaintext."<br>";
    }
}

I am unable get the class value. How can I achieve this?

update I am traversing through this source. Am I wrong in logic?

enter image description here

From your code, I assume you are looking for <li> elements without the class viewAll.

You may need to check whether the class attribute exists first. Try this:

foreach($sub->children() as $child){
    # child element doesn't have a class attrib
    if (! $child->hasAttribute('class') || 
    # or child element has a class but it is not 'viewAll'
       ($child->hasAttribute('class') && $child->getAttribute('class') !== 'viewAll'))
        echo $child->plaintext."<br>";
    }
}

Or, in the simple-html-dom style, this:

$lis = $html->find('ul li[!class]');
foreach ($lis as $li) {
    echo $li->plaintext."<br>";
}