3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // Load up the HTML in DOMDocument $doc = new DOMDocument; $doc->loadHTML( '<a class="modal">Stuff</a>'); // Or: $doc->loadHTML( $this->form->getInput('image_intro', 'images')); // Create a new XPath object to find the correct <a> tags $xpath = new DOMXPath( $doc); // Iterate over all <a class="modal"> tags foreach( $xpath->query( "//a[@class='modal']") as $a) { // Set the class attribute correctly $a->setAttribute( 'class', $a->getAttribute( 'class') . '-link'); echo $doc->saveHTML( $a); // Print the fixed <a> tag }
Output for 5.3.6 - 7.1.0
<a class="modal-link">Stuff</a>
Output for 5.0.0 - 5.3.5
Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/Zbdrd on line 13
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/Zbdrd on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/Zbdrd on line 3