Return single item from $element with simple-html-dom-parser [closed]
-
14-11-2019 - |
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;
}
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