user3103798
user3103798

Reputation: 15

How do I get this text using PHP Simple HTML dom?

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.

Upvotes: 1

Views: 132

Answers (2)

Vladimir
Vladimir

Reputation: 461

Or you can find < p > tag elements first:

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

Upvotes: 0

The fourth bird
The fourth bird

Reputation: 163362

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);
}

Upvotes: 1

Related Questions