3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cssClasses = [ 'container' => 'width: 100%;padding-right: 15px;padding-left: 15px;margin-right: auto;margin-left: auto;', 'card' => 'position: relative;display: -ms-flexbox;display: flex;-ms-flex-direction: column;flex-direction: column;min-width: 0;word-wrap: break-word;background-color: #fff;background-clip: border-box;border: 1px solid rgba(0, 0, 0, 0.125);border-radius: 0.25rem;' ]; $html = <<<'EOD' <div class="container"> 01 <div class="card"> 02 </div> </div> EOD; $dom = new DOMDocument; $dom->loadHTML($html); $divNL = $dom->getElementsByTagName('div'); for ($i = $divNL->length - 1; $i >= 0; $i--) { $node = $divNL->item($i); $table = $dom->createElement('table'); $tr = $dom->createElement('tr'); $td = $dom->createElement('td'); $table->appendChild($tr); $tr->appendChild($td); foreach ($node->attributes as $attr) { $td->appendChild($attr); } $styles = array_reduce( preg_split('~\s+~u', $td->getAttribute('class')), function($c, $i) use ($cssClasses) { return isset($cssClasses[$i]) ? $cssClasses[$i] . $c : $c; }, $td->getAttribute('style') ); if ( !empty($styles) ) $td->setAttribute('style', $styles); foreach ($node->childNodes as $childNode) { $td->appendChild($childNode->cloneNode(true)); } $node->parentNode->replaceChild($table, $node); } $result = ''; foreach ($dom->getElementsByTagName('body')->item(0)->childNodes as $childNode) { $result .= $dom->saveHTML($childNode); } echo $result;
Output for git.master, git.master_jit
<table><tr><td class="container" style="width: 100%;padding-right: 15px;padding-left: 15px;margin-right: auto;margin-left: auto;"> 01 <table><tr><td class="card" style="position: relative;display: -ms-flexbox;display: flex;-ms-flex-direction: column;flex-direction: column;min-width: 0;word-wrap: break-word;background-color: #fff;background-clip: border-box;border: 1px solid rgba(0, 0, 0, 0.125);border-radius: 0.25rem;"> 02 </td></tr></table> </td></tr></table>

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:
12.63 ms | 409 KiB | 5 Q