我这里有一段代码,它从目录中获取最后修改的文件。但是,我希望它排除任何上面写有“占位符”一词的文件。我该如何修改它以排除这些文件,特别是因为在其页面上写有“占位符”的文件通常是最后修改的文件?
这是我拥有的代码:
<?php
$dir = "path goes here";
$pattern = '\.(php)$'; // check only file with these ext.
$newstamp = 0;
$newname = "";
if ($handle = opendir($dir)) {
while (false !== ($fname = readdir($handle))) {
// Eliminate current directory, parent directory
if (ereg('^\.{1,2}$',$fname)) continue;
// Eliminate other pages not in pattern
if (! ereg($pattern,$fname)) continue;
$timedat = filemtime("$dir/$fname");
if ($timedat > $newstamp) {
$newstamp = $timedat;
$newname = $fname;
}
}
}
closedir ($handle);
$name = basename($newname,".php");
echo "<b><span class='latestch'>Latest Chapter:</span></b> <a href=url-path-goes-here".$newname."> $name</a>";
?>