getSettings()似乎只讀取並輸出目錄中的1個settings.php文件。我怎樣才能讀取並輸出所有的settings.php文件內容?PHP遞歸目錄句柄問題
<?php
$config = array("os"=>"windows","directory"=>"../Core-Stack/Themes/","ignore"=>array('_vti_cnf','cgi-bin','.','..'));
function getSettings($dir, $issubdir = false) {
global $config, $SETTINGS;
if ($config['os'] == "unix")
$delimiter = "/";
else if ($config['os'] == "windows")
$delimiter = "\\";
if (!file_exists($dir) || !is_dir($dir) || !is_readable($dir)) {
echo "Error: \"$dir\" is not a directory, or I cannot read it properly.";
return 0;
} else if ($od = opendir($dir)) {
while (($file = readdir($od)) !== false) {
if (!in_array($file, $config['ignore'])) {
$path = $dir . $delimiter . $file;
if (is_dir($path))
getSettings($path, true);
elseif (is_file($path) && $file == "settings.php")
include ($path);
}
}
closedir($od);
}
}
getSettings($config['directory'], true);
echo "Theme Name: ";
echo $SETTINGS['theme_name'];
echo "<br>";
echo "Theme Creator: ";
echo $SETTINGS['theme_creator'];
echo "<br>";
echo "Theme Version: ";
echo $SETTINGS['theme_version'];
echo "<br>";
echo "Theme Creation Date: ";
echo $SETTINGS['theme_creation_date'];
?>
你不需要做操作系統切你知道,你可以自己設置正確的目錄分隔符。您可以使用DIRECTORY_SEPARATOR常量,它始終包含正在運行的操作系統的正確分隔符字符序列 – GordonM 2011-04-28 13:30:16