下面的代码将回显每个文件中的关键字,是否可以让结果(每个文件的关键字)按字母顺序显示。
<?php
$files = (glob('{beauty,careers,education,entertainment,pets}/*.php', GLOB_BRACE));
$selection = $files;
$files = array();
$keywords = $matches[1];
foreach ($selection as $file) {
if (basename($file) == 'index.php') continue;
if (basename($file) == 'error_log') continue;
$files[] = $file;
}
foreach($files as $file) {
$title = str_replace('-', ' ', pathinfo($file, PATHINFO_FILENAME));
$content = file_get_contents($file);
if (!$content) {
echo "error reading file $file<br>";
}
else {
preg_match("/keywords = \"(.*?)\"/i", $content, $matches);
$keywords = $matches[1];
}
$results .= '<li><a href="http://domain.com/' . htmlentities($file, ENT_QUOTES) . '">'.$keywords.'</a></li>';
}
?>
<?=$results?>