PHP Simple HTML DOM Parser how to get TR only from first table

怎甘沉沦 提交于 2019-12-06 05:13:16

You could try something as simple as this:

foreach($html->find('tr') as $tr) {
    // do something with $tr
    break; // stop now
}

Or specify it like this:

$tr = $html->find('tr', 0); // zero based index selector

You should be able to do this easily with just a few lines:

$table = $html->find('table', 0);
foreach($table->find('table') as $tb) {
foreach($tb->find('tr') as $tr) {
        echo $tr;
    }
}

result:

<tr>
 <td>...</td>
</tr>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!