如何检查 domdocument 是否有项目


How to check whether domdocument has items

如何检查 domdocument 是否有项目

法典:

 $iframe =  $dom->getElementsByTagName('iframe');

 foreach ($iframe as $if) {
    //how to check whether $if has items for
     // $if->item(0) so that I can access it without errors?
 }

测试节点是否具有具有hasChildNodes()的子节点

 foreach ($iframe as $if) {
    if ($if->hasChildNodes()) {
       // first child is $if->childNodes->item(0)
    }
 }

你可以使用 like 进行检查

if($if -> hasChildNodes()) { ... }

相关文章: