ここに、ディレクトリから最後に変更されたファイルを取得するコードのスニペットがあります。ただし、「プレースホルダー」という単語が書かれているファイルは除外したいと思います。特に「プレースホルダー」がページに書かれているファイルは通常最後に変更されたファイルであるため、これらのファイルを除外するようにこれを変更するにはどうすればよいですか?
これが私が持っているコードです:
<?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>";
?>