<?php function modify_href( $href ) { return $href . '/modified'; } $string = '<div> <a href="http://somelink" class="possible-class">text</a> <a href="http://anotherlink">other text</a> </div>'; $doc = new DomDocument(); $fragment = $doc->createDocumentFragment(); $fragment->appendXML($string); $doc->appendChild($fragment); $xpath = new DOMXPath($doc); $elements = $xpath->query("//div/a"); foreach ($elements as $element) { $element->setAttribute("href", modify_href($element->getAttribute("href"))); } echo $doc->saveHTML();
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`