Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Stop List After xx Number of Entries


rocknbil - 5:16 pm on Aug 19, 2010 (gmt 0)


Right, I'd be using that . . .but given what you have here,


<?php
function listFolders($path,$recurse_limit=null){
$counter=0;
$dirlist=$dir_errors=null;
//if the path cannot be found
if(! is_dir($path)){
return Array (null,"The specified path could not be found.");
}//if
//the path is valid
else{
foreach($path as $i){
$counter++;
$dirlist .= "<li>$i</li>\n"; // Retentive about semantics is Padawan
if ($recurse_limit and ($counter >= $recurse_limit)) {
break;
}
}//foreach
}//else
return Array($dirlist,$dir_errors);
}//listFolders
?>
//
<?php
// assuming GLOB_ONLYDIR is a constant
$dir_limit = 10;
list($dirs,$errors) = listFolders(GLOB_ONLYDIR,$dir_limit);
echo ($errors)?"Error: $errors":"<ul>$dir</ul>";
?>


You really don't need $dir_errors as you only have one error check, but it may be that you might add more later. So instead of

return Array (null,"The specified path could not be found.");

you could do

$dir_errors .= "<li>The specified path could not be found.</li>";

and

$dir_errors .= "<li>Some other error</li>";

then they both return at the end of the function.


Thread source:: http://www.webmasterworld.com/php/4188950.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com