在代码中,
$c = $node->getAttribute('class');
if (exist $c) {do somthing};
如何检查?
两者的返回值(none和empty)相同(!):
属性的值,如果找不到具有给定名称的属性,则为空字符串。
PS:为什么(??)它不返回NULL表示"没有属性"?
参见DOMElement::hasAttribute
if ($node->hasAttribute('class')) {do somthing};
您可能正在寻找DOMElement::hasAttributeNS
DOMElement::hasAttributeNS--检查属性是否存在
像
if ($node->hasAttribute('class'))
{
//code
}