有人可以解释一下这段代码。在阅读拉里ullman的关于PHP的书,我不知道这部分。在此先感谢!!
$search_dir = '.';
$contents = scandir($search_dir);
print '<h2>Directories</h2>
<ul>';
foreach ($contents as $item) {
if ( (is_dir($search_dir . '/' . $item)) AND (substr($item, 0, 1) != '.') ) {
print "<li>$item</li>\n";
}
}
print '</ul>';
答案 0 :(得分:1)
它显示当前目录中所有目录的列表
答案 1 :(得分:0)
我将使用注释重新发布您的代码,以解释每行的内容。
$search_dir = '.'; //Set the directory to search. "." means the current one.
$contents = scandir($search_dir); //scan the directory and return its results into $contents
print '<h2>Directories</h2>
<ul>';
foreach($contents as $item) { //Iterate through the array and for each item...
//If the item is a directory AND it doesn't start with a . (which means the current one)...
if ((is_dir($search_dir.'/'.$item)) AND(substr($item, 0, 1) != '.')) {
print "<li>$item</li>\n"; //Print it
}
}
print '</ul>';
简而言之,它打印出运行脚本的目录中的目录输出。