Answer the question
In order to leave comments, you need to log in
Why is html attribute not showing through php xpath?
Why is the html attribute not showing through php?
https://wtools.io/php-sandbox/xF
Works - //div[@class="remove-me"] or //div[@class="remove-me"]/text()
Not working - //div[@class="remove-me"]/@id
Answer the question
In order to leave comments, you need to log in
Solved helped in another site
<?php
$content = '<div class="keep-me">Keep this div</div><div class="remove-me" id="test">Remove this div</div>';
$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML($content);
libxml_clear_errors();
$xPath = new DOMXpath($dom);
$domNodeList = $xPath->query('//div[@class="remove-me"]/@id');
$ids = []; // container of deleted elements
foreach ( $domNodeList as $domElement ) {
$ids[] = $domElement->nodeValue;
}
echo $ids[0];
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question