April 13, 2012
How to check whether domdocument has items
Question by BetterMan21
How to check whether domdocument has items
code:
$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?
}
Answer by Michael Berkowski
Test if the node has child nodes with hasChildNodes()
foreach ($iframe as $if) {
if ($if->hasChildNodes()) {
// first child is $if->childNodes->item(0)
}
}