gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:10:20 25 4
gpt4 key购买 nike

在代码中,

 $c = $node->getAttribute('class');
if (exist $c) {do somthing};

如何检查?

return value of both, none and empty, are the same(!) :

The value of the attribute, or an empty string if no attribute with the given name is found.

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

最佳答案

DOMElement::hasAttribute

if ($node->hasAttribute('class')) {do somthing};

关于php - DOMElement,如何(做一个简单的)检查属性是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25730186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com