<?php $document = "<html> <a href='do not keep'><div>DO NOT KEEP1</div></a> <a href='do keep' data-link='keepLink'>Keep Link</a> <a href='do not keep'>DO NOT KEEP2</a> </html>"; $dom = new DOMDocument; $dom->loadXml($document); // load the file $xpath = new DOMXPath($dom); $nodes = $xpath->query('//a[not(@data-link=\'keepLink\')]'); // search for links that do not have the 'data-link' attribute set to 'keepLink' foreach($nodes as $element){ $textInside = $element->nodeValue; // get the text inside the link $parentNode = $element->parentNode; // save parent node $parentNode->replaceChild(new DOMText($textInside), $element); // remove the element } $myNewHTML = $dom->saveHTML(); // see http://php.net/manual/ro/domdocument.savehtml.php for limitations such as auto-adding of doc-type echo $myNewHTML;
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`