Question

New to the simple-html-dom-parser and have a question.

Assuming $element is an array, how can I return a specific item (an image in this case) from the array. I have tried $element[1] and $element->childNodes ([1]) to no avail.

$html = file_get_html($url);

foreach($html->find('img') as $element)
    {
    echo $element;
    }

Simple-html-dom-parser api

Was it helpful?

Solution

According to the documentation you posted, find takes a second optional argument which is the index of the element you're looking for. So, for example, you could do $html->find('img', 1) and it would return the first img element it could find.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top