Rik Nijdeken Rik Nijdeken - 11 months ago 59
HTML Question

Find id automatically for SimpleHTMLDom

I am trying to build a really minimalistic API for Zoover (The holiday review website) and I want to load in the testimonials but they create a different id for each testimonial. Does someone know how I can get the id of the


This is the code I have already, this just echo's the first testimonial because they all have a different id:


$html = file_get_html("http://www.zoover.nl/indonesie/lombok/senggigi/campi-sorga/villa/?s=P2xuZz1MYW5ndWFnZV9BTEwmcGFydHlDb21wRmx0SWQ9JnRzdF9wZ3NpemU9MTAmc29ydD1jb250cmlidXRpb24tZGF0ZQ==&page=0");

foreach($html->find('#testimonial13247814 > article > header > h3') as $element)
echo $element . "<br>";

Hope someone knows how I can fix this.

Answer Source

Obviously, don't point to the ID, use the parent <ul> then get its <li> children instead:

$elements = $html->find('ul.zvr-contributions-list > li > article > header > h3');
if(!empty($elements)) {
    foreach($elements as $element) {
        echo $element;