3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $html = <<<EOF <p>asdasd</p> <img src="img1.jpg" style="width: 180px;"> <p>asdasd</p> <img src="img2.jpg" style="width: 180px;"> <p>asdasd</p> <img src="img3.jpg" style="width: 180px;"> <p>asdasd</p> <img src="img4.jpg" style="width: 180px;"> EOF; $dom=new DOMDocument(); $dom->loadHTML($html); $imgs = $dom->getElementsByTagName("img"); foreach($imgs as $img){ $img->setAttribute( 'src' , 'thumbnail.php?img=' . $img->getAttribute('src') ); } echo $dom->saveHTML();
Output for 5.3.3 - 7.1.0
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><p>asdasd</p> <img src="thumbnail.php?img=img1.jpg" style="width: 180px;"><p>asdasd</p> <img src="thumbnail.php?img=img2.jpg" style="width: 180px;"><p>asdasd</p> <img src="thumbnail.php?img=img3.jpg" style="width: 180px;"><p>asdasd</p> <img src="thumbnail.php?img=img4.jpg" style="width: 180px;"></body></html>
Output for 5.0.0 - 5.3.2
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <p>asdasd</p> <img src="thumbnail.php?img=img1.jpg" style="width: 180px;"><p>asdasd</p> <img src="thumbnail.php?img=img2.jpg" style="width: 180px;"><p>asdasd</p> <img src="thumbnail.php?img=img3.jpg" style="width: 180px;"><p>asdasd</p> <img src="thumbnail.php?img=img4.jpg" style="width: 180px;"> </body></html>
Output for 4.3.2 - 4.4.1, 4.4.3 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/1Eh7N on line 17
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: domdocument in /in/1Eh7N on line 18
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/1Eh7N on line 17