我想要使用 PHP DOMXPath 查询的多个标签(td 和 th)。
我该怎么做?
您可以使用|
(联盟)运营商。这是一个例子:
$doc = new DOMDocument();
$doc->loadHTML('<table>
<tr>
<th>table header</th>
<td>table cell</td>
</tr>
</table>');
$xpath = new DOMXPath($doc);
$rows = $xpath->query('//tr'); // select all <tr> elements anywhere in the document
$cols = $xpath->query('./th | ./td', $rows->item(0)); // select all <th>/<td> from context
// where context = first row
echo $cols->length; // 2
echo $cols->item(0)->nodeValue; // table header
echo $cols->item(1)->nodeValue; // table cell
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)