3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<h2>Spiders</h2> <h2>Beetles</h2> <h3>External morphology</h3> <h4>Head</h4> <h4>Thorax</h4> <h4>Legs</h4> <h3>Anatomy and physiology</h3> <h2>Ants</h2>'; preg_match_all('/<h(\d)>([^<]+)/', $html, $matches); $cdepth = $matches[1][0] - 1; foreach ($matches[1] as $key => $depth) { if ($depth > $cdepth) { echo "\n" . str_repeat(' ', $cdepth * 4) . "<ol>\n"; } elseif ($depth < $cdepth) { echo "</li>\n" . str_repeat(' ', $depth * 4) . "</ol>\n" . str_repeat(' ', $depth * 4) . "</li>\n"; } else { echo "</li>\n"; } $cdepth = $depth; echo str_repeat(' ', $cdepth * 4) . "<li><a href=\"{$matches[2][$key]}\">{$matches[2][$key]}</a>"; } while ($cdepth-- >= $matches[1][0]) { echo "</li>\n" . str_repeat(' ', $cdepth * 4) . "</ol>\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
<ol> <li><a href="Spiders">Spiders</a></li> <li><a href="Beetles">Beetles</a> <ol> <li><a href="External morphology">External morphology</a> <ol> <li><a href="Head">Head</a></li> <li><a href="Thorax">Thorax</a></li> <li><a href="Legs">Legs</a></li> </ol> </li> <li><a href="Anatomy and physiology">Anatomy and physiology</a></li> </ol> </li> <li><a href="Ants">Ants</a></li> </ol>

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:
164.84 ms | 407 KiB | 5 Q