我应该能够修改通过以下查询获得的输出:$ods22_tmp_t =$finder->query("//*[contains(@class, 'PPToggle')]");输出如下: <tr class="PPToggle" CO="8465"> <td PT="0" PABloccato="True" Validato="False" MeseValidato="False"><div title="HD09001300 dalle ore 09:00 alle ore 13:00" class="cellePiano" PT="1428" ColoreTesto="#000000" ColoreSfondo=""> HD09001300 </div><div title="HD14001800 dalle ore 14:00 alle ore 18:00" class="cellePiano" PT="142" ColoreTesto="#000000" ColoreSfondo=""> HD14001800 </div></td><td PT="0" PABloccato="True" Validato="False" MeseValidato="False"><div title="HD10001400 dalle ore 10:00 alle ore 14:00" class="cellePiano" PT="142219" ColoreTesto="#000000" ColoreSfondo=""> HD10001400 </div><div title="HD15001900 dalle ore 15:00 alle ore 19:00" class="cellePiano" PT="142820" ColoreTesto="#000000" ColoreSfondo=""> HD15001900 </div></td><td PT="0" PABloccato="True" Validato="False" MeseValidato="False"><div title="HD13001700 dalle ore 13:00 alle ore 17:00" class="cellePiano" PT="142882" ColoreTesto="#000000" ColoreSfondo=""> HD13001700 </div><div title="HD18002200 dalle ore 18:00 alle ore 22:00" class="cellePiano" PT="14287" ColoreTesto="#000000" ColoreSfondo=""> HD18002200 </div></td> </tr>我想在 TR 和 TD 之间添加这个标签:<th>Operator</th>我如何指定我想在两个之间添加一个标签?
1 回答
慕尼黑5688855
TA贡献1848条经验 获得超2个赞
您需要创建您之后的元素,然后用于insertBefore()在文档中定位这个新节点($node->firstChild首先用于定位它)......
$dom = new DOMDocument;
$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
$ods22_tmp_t = $xpath->query("//*[contains(@class, 'PPToggle')]");
foreach($ods22_tmp_t as $node) {
$th = $dom->createElement("th", "Operator");
$node->insertBefore($th, $node->firstChild);
}
- 1 回答
- 0 关注
- 121 浏览
添加回答
举报
0/150
提交
取消