3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function treeList($path = "") { $prefix = ($path == "") ? $_SERVER['DOCUMENT_ROOT'] : ""; $return = preg_replace("#(.*)/(.*)$#u","\$1",$path); echo ' <ul> '; echo ' <li><a href="?path='.$return.'">[...назад...]</a></li> '; foreach (glob($_SERVER['DOCUMENT_ROOT']."$path/*") as $item) { $isdir = (is_dir($item)) ? true : false; $item = str_replace(array($_SERVER['DOCUMENT_ROOT'],"//"),array("","/"),$item); if ($isdir) echo ' <li><b><a href="?path='.$item.'">'.$item.'</a></b></li> '; else echo ' <li>'.$item.'</li> '; } echo ' </ul> '; } $path = (isset($_GET['path'])) ? $_GET['path'] : ""; header("Content-Type: text/html; charset=utf-8"); treeList($path);
Output for 5.2.3 - 7.1.0
<ul> <li><a href="?path=">[...назад...]</a></li> </ul>
Output for 4.3.0 - 4.3.6, 4.3.9 - 5.2.2
Notice: Undefined index: DOCUMENT_ROOT in /in/nSLvQ on line 4 <ul> <li><a href="?path=">[...назад...]</a></li> Notice: Undefined index: DOCUMENT_ROOT in /in/nSLvQ on line 12 </ul>
Output for 4.3.7 - 4.3.8
Notice: Undefined index: DOCUMENT_ROOT in /in/nSLvQ on line 4 <ul> <li><a href="?path=">[...назад...]</a></li> Notice: Undefined index: DOCUMENT_ROOT in /in/nSLvQ on line 12 Warning: Invalid argument supplied for foreach() in /in/nSLvQ on line 12 </ul>