-1
我想用這些條件在一起的XPath查詢在PHP如何用XPath選擇兩個特定的標籤類並全部刪除?
//*[contains(concat(' ', normalize-space(@class), ' '), ' metadata ')]
和
*[contains(concat(' ', normalize-space(@class), ' '), ' mw-editsection ')]
我應該怎麼辦?
我想下面的東西,但它不工作:
$dom = new DOMDocument;
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8"));
$xPath = new DOMXPath($dom);
$nodes = $xPath->query('//*[contains(concat(\' \', normalize-space(@class), \' \'), \' metadata \') and //*contains(concat(\' \', normalize-space(@class), \' \'), \' mw-editsection \ ]');
if($nodes->item(0)) {$nodes->item(0)->parentNode->removeChild($nodes->item(0));}
$content = $dom->saveHTML();
,並有我的DOM結構中一個以上metadata
和mw-editsection
班,我想刪除所有元數據和MW-Editsection的類
喜歡
<body>
...
<div class="metadata"> abc </div>
<div class="mw-editsection"> xyz </div>
...
<div class="metadata"> 123 </div>
<div class="metadata"> 456 </div>
<div class="metadata"> 789 </div>
<div class="mw-editsection"> abc </div>
...
</body>
我想將它們全部刪除。