3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $string = '<ul><li><a href="test.php">Test</a>(10)</li></ul>'; echo $string; $dom_document = new DOMDocument(); $dom_document->loadHTML($string); $new_string = ""; foreach($dom_document->getElementsByTagName('ul') as $ul){ // For all ul. $new_string .= "<ul>"; foreach($ul->childNodes as $li){ // For all li. $new_string .= "<li>"; $i=0; foreach($li->childNodes as $a){ if(isset($a->attributes[0]->value)){ $href = $a->attributes[0]->value; } if($i===0){ $new_string .= '<a href="'.$href.'">'; } $new_string .= $a->nodeValue; $i++; } $new_string .= "</a>"; $new_string .= "</li>"; } $new_string .= "</ul>"; } echo $new_string;
Output for 5.6.3 - 5.6.30, 7.0.0 - 7.3.0rc3
<ul><li><a href="test.php">Test</a>(10)</li></ul><ul><li><a href="test.php">Test(10)</a></li></ul>
Output for hhvm-3.15.4
<ul><li><a href="test.php">Test</a>(10)</li></ul> Fatal error: Uncaught Error: Object does not implement ArrayAccess in /in/pWLiL:18 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.2
<ul><li><a href="test.php">Test</a>(10)</li></ul> Fatal error: Cannot use object of type DOMNamedNodeMap as array in /in/pWLiL on line 18
Process exited with code 255.