php遍历目录下文件,并读取内容

<?php
echo "<h2>遍历目录下文件,并读取内容</h2><br>\n";
function listDir($dir)
{
if(is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if((is_dir($dir."/".$file)) && $file!="." && $file!="..")
{
echo "<b>",$file,"/</b>";
listDir($dir."/".$file."/");
}
else
{
if($file!="." && $file!="..")
{
echo '<h3>'.$file."</h3><br>";
//逐行读取数据
$file = fopen($dir.''.$file,"r");
while(! feof($file))
{
echo '<xmp>'.fgets($file). "</xmp>";
}
fclose($file);
}
} }
closedir($dh);
}
}
}
//开始运行
//
echo "<b>文档标题</b><br/>";
listDir("D:/1/a/b/c/");
?>

  

上一篇:Lua C++ Binding之Lunar, Luna


下一篇:git提交时忽略指定文件