dongshun7312 2015-10-30 23:20
浏览 137
已采纳

如何使用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.

  • 写回答

2条回答 默认 最新

  • douzhan1935 2015-10-31 01:20
    关注

    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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?