HTML:
<div class="vm-customfield-cart">
<span class="product-field-type-S">Some important text</span><br />
<span class="product-field-type-S">Lorem ipsum dolor</span><br />
</div>
如何删除包含文本Lorem ipsum
的跨度。 Lorem ipsum
之后的所有内容都可以变量,这就是我需要按Lorem ipsum
搜索jsut的原因。
我的代码如下:
$dom = new DOMDocument;
$dom->loadHTML($html);
$xp = new DOMXPath($dom);
$spanNodeList = $xp->query("//*[contains(., 'Lorem ipsum')]");
foreach ($spanNodeList as $spanNode) {
//I have no idea how to clean it out
}
最终结果应如下所示:
<div class="vm-customfield-cart">
<span class="product-field-type-S">Some important text</span><br />
</div>
答案 0 :(得分:0)
尝试
$spanNode->parentNode->removeChild($spanNode);