3v4l.org

run code in 300+ PHP versions simultaneously
<?php $content = '<figure class="image image-style-align-left"><img src="https://placekitten.com/g/200/300"></figure><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>'; $dom = new DOMDocument(); libxml_use_internal_errors(true); // this needs to be encoded otherwise special characters get messed up. $domPart = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8"); $dom->loadHTML($domPart, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $domFigures = $dom->getElementsByTagName('figure'); foreach ($domFigures as $domFigure) { $img = $domFigure->getElementsByTagName('img')[0]; if ($img) { $img->setAttribute('src', "https://placekitten.com/g/400/500"); } } $result = $dom->saveHTML(); print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in /in/AgIjB on line 9 <figure class="image image-style-align-left"><img src="https://placekitten.com/g/400/500"><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p></figure>

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:
38.97 ms | 406 KiB | 5 Q