首页 热点专区 小学知识 中学知识 出国留学 考研考公
您的当前位置:首页正文

php遍历目录

来源:要发发知识网

(创意:遍历目录 在线编辑文件 的 小工具)

// 注意在 4.0.0-RC2 之前不存在 !== 运算符

if ($handle=opendir('/path/to/files')) {

echo"Directory handle:$handle\n";

echo"Files:\n";

/* 这是正确地遍历目录方法 */

while (false!== ($file=readdir($handle))) {

echo"$file\n";

}

/* 这是错误地遍历目录的方法 */

while ($file=readdir($handle)) {

echo"$file\n";

}

closedir($handle);

}

?>

if ($handle=opendir('.')) {

while (false!== ($file=readdir($handle))) {

if ($file!="."&&$file!="..") {

echo"$file\n";

}

}

closedir($handle);

}

?>

显示全文