DOMElement,如何(做一个简单的)检查属性是否存在?

Pet*_*uss 2 php dom

在一段代码中,

 $c = $node->getAttribute('class');
 if (exist $c) {do somthing};
Run Code Online (Sandbox Code Playgroud)

如何检查?

none 和 empty返回值是一样的(!)

属性的值,如果未找到具有给定名称的属性,则为空字符串。

PS:为什么(??)它不会为“没有属性”返回NULL?

clo*_*eek 5

DOMElement::hasAttribute

if ($node->hasAttribute('class')) {do somthing};
Run Code Online (Sandbox Code Playgroud)