从php

时间:2018-03-17 12:29:07

标签: php html

我有一个包含多行的html表,每行有多列。一行的样本看起来像这样。

<table class ="classt">
    <tbody>
        <tr class="row">
            <td height="20" valign="top" class="mosttext-new">data</td>
            <td height="20" valign="top" class="mosttext-new"> data</td>
            <td height="20" valign="top" class="mosttext-new">data</td> 
        </tr>
    </tbody>
</table>

我试图在php脚本中提取所有这样的td元素。

foreach($html->find('table.classt') as $e){
         foreach ($e->find('tr.row') as $tr){
            foreach ($tr->find('td') as $td){
                    $text = $td->innertext;
            }
        }
    }

但在$ tr中我没有使用td标签获取行详细信息。它只是用这样的双引号来整个行

&#34;数据数据&#34;

所以我的第三个循环无法找到td,因为$ tr没有td标签。

对此有什么想法吗?

1 个答案:

答案 0 :(得分:5)

我认为你必须在&#39; td&#39;之后提及课程名称。接着是&#39;。&#39;像这样

 foreach ($tr->find('td.mosttext-new') as $td)

希望这可以解决您的问题。一切顺利。

相关问题