acctman
acctman

Reputation: 4349

Simple HTML Dom: check if tag exist

I'm trying to check if there is and image after the tag, and if there is grab the width value. the method i'm using below is not working

$element = $html->find("td", 23);
if ($element->innertext != null) {
    $element = $html->find("td img[src=http://pictures.domain.com/images/7.gif]");
    echo $element->width . '<br />';        
} else {
   echo "empty";
}

Upvotes: 3

Views: 7688

Answers (1)

Jasper
Jasper

Reputation: 76003

I got around this problem by using is_object() and is_array().

When you search for a single element, an object is returned. When you search for a set of elements, an array of objects is returned.

$td = $html->find("td", 23) is searching for a single element, so using the following will check for the existence of the searched-for element:

$td = $html->find("td", 23);
if (is_object($td)) {
    //continue
}

Upvotes: 3

Related Questions