3v4l.org

run code in 300+ PHP versions simultaneously
<?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;
Output for git.master, git.master_jit, rfc.property-hooks
<html> DO NOT KEEP1 <a href="do%20keep" data-link="keepLink">Keep Link</a> DO NOT KEEP2 </html>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
141.81 ms | 405 KiB | 5 Q