3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <p><iframe allowfullscreen="" class="media-element file-default" data-fid="2219" data-media-element="1" frameborder="0" height="360" src="https://www.youtube.com/embed/sNEJOm4hSaw?feature=oembed" width="640"></iframe></p> HTML; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); foreach ($dom->getElementsByTagName('iframe') as $iframe) { $a = $dom->createElement('a'); $a->setAttribute('href', $iframe->getAttribute('src')); $a->nodeValue = "Link to youtube"; $iframe->parentNode->replaceChild($a, $iframe); } echo $dom->saveHTML();
based on 840NG
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.26, 7.4.0 - 7.4.14, 8.0.0
<p><a href="https://www.youtube.com/embed/sNEJOm4hSaw?feature=oembed">Link to youtube</a></p>
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.1, 5.1.3 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Notice: Use of undefined constant LIBXML_HTML_NOIMPLIED - assumed 'LIBXML_HTML_NOIMPLIED' in /in/UKqAX on line 7 Notice: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' in /in/UKqAX on line 7 Warning: DOMDocument::loadHTML() expects exactly 1 parameter, 2 given in /in/UKqAX on line 7
Output for 5.1.2
Notice: Use of undefined constant LIBXML_HTML_NOIMPLIED - assumed 'LIBXML_HTML_NOIMPLIED' in /in/UKqAX on line 8 Notice: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' in /in/UKqAX on line 8 Warning: DOMDocument::loadHTML() expects exactly 1 parameter, 2 given in /in/UKqAX on line 8
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.1, 4.4.3 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/UKqAX on line 6
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: domdocument in /in/UKqAX on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/UKqAX on line 6