簡體   English   中英

如何檢查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)
    }
 }

您可以使用喜歡檢查

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM