3v4l.org

run code in 300+ PHP versions simultaneously
<?php $inliner_bypass_matches_total = 0; $inliner_bypass_matches = array(); $the_html = '<style class="sp_bypassInliner">div.class {width:100%}</style>'; $dom = new DOMDocument(); $dom->formatOutput = false; $dom->preserveWhiteSpace = false; $dom->strictErrorChecking = false; $dom->validateOnParse = false; $the_html = str_replace('&nbsp;', '@nbsp;', $the_html); $dom->loadHTML(mb_convert_encoding('<?xml version="1.0" encoding="UTF-8"?>' . "\n" .$the_html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); $nodes = $xpath->query("//*[contains(@class, 'sp_bypassInliner')]"); $node_count = $nodes->length; if ($node_count > 0) { // Work from the bottom up, so we don't mess anything up. for ($i=$node_count; $i>0; --$i) { $node = $nodes->item($i-1); $inliner_bypass_matches_total++; $html_fragment = $node->nodeValue; $inliner_bypass_matches[$inliner_bypass_matches_total] = $html_fragment; $inliner_bypass_tags = $dom->createDocumentFragment(); $inliner_bypass_tags->appendXML("<!--sp_bypassInliner$inliner_bypass_matches_total-->"); $node->parentNode->replaceChild($inliner_bypass_tags, $node); } $the_html = $dom->saveHTML($dom->documentElement); // $the_html = dom_savehtml_cleanup($the_html); } else $the_html = str_replace('@nbsp;', '&nbsp;', $the_html); echo $dom->saveHTML($the_html[0]);
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in /in/dTi4e on line 12 Fatal error: Uncaught TypeError: DOMDocument::saveHTML(): Argument #1 ($node) must be of type ?DOMNode, string given in /in/dTi4e:44 Stack trace: #0 /in/dTi4e(44): DOMDocument->saveHTML('<') #1 {main} thrown in /in/dTi4e on line 44
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33
Fatal error: Uncaught TypeError: DOMDocument::saveHTML(): Argument #1 ($node) must be of type ?DOMNode, string given in /in/dTi4e:44 Stack trace: #0 /in/dTi4e(44): DOMDocument->saveHTML('<') #1 {main} thrown in /in/dTi4e on line 44
Process exited with code 255.
Output for 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.33, 7.4.0 - 7.4.33
Warning: DOMDocument::saveHTML() expects parameter 1 to be DOMNode, string given in /in/dTi4e on line 44

preferences:
184.95 ms | 412 KiB | 5 Q