Skip to content

Instantly share code, notes, and snippets.

@apipkin
Created February 23, 2010 16:20
Show Gist options
  • Save apipkin/312360 to your computer and use it in GitHub Desktop.
Save apipkin/312360 to your computer and use it in GitHub Desktop.
function loopDir($path = null) {
if($path === null) {
$path = '.';
}
$d = dir($path);
$ret = '';
while(false !== ($f = $d->read())) {
if($f === '.' || $f === '..') {
continue;
}
$ret .= '<li><span>' . $f . '</span>';
if(is_dir($d->path . $f)) {
$ret .= '<ul>' . loopDir($d->path . $f . '/') . '</ul>';
}
$ret .= '</li>';
}
return $ret;
}
echo '<ul>' . loopDir() . '</ul>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment