1

Assuming I have this HTML Code in an HTML source:

<div class="info">
    <p><span class="strong">Score</span>4.32/5</p>
    <p><span class="strong">Type</span>TV</p>
    <p><span class="strong">Episodes</span>13</p>
    <p><span class="strong">Status</span>Ongoing</p>
    <p><span class="strong">Aired</span>Oct 3, 2015 - Dec 26, 2015</p>
    <p><span class="strong">Age</span>PG-13 - Teens 13 or older</p>
</div>

How do I use the PHP Simple HTML dom to get the text 4.32 from above? I tried

foreach($info_html->find('.strong') as $library) {
    $rating = $library->innertext;
    var_dump($rating);
}

But that only gives me the text "score", but I want 4.32.

2 Answers2

1

Maybe this will give you the result you are looking for:

foreach($info_html->find('div.info p') as $library) {
    $rating = $library->find('text', 1)->innertext;
    var_dump($rating);
}
The fourth bird
  • 154,723
  • 16
  • 55
  • 70
0

Or you can find < p > tag elements first:

foreach($info_html->find('p') as $library) {
        $rating = $library->find('text', 1)->plaintext;
        var_dump($rating);
}
Vladimir
  • 441
  • 1
  • 4
  • 14