我正在创建一个文章系统,我需要include
目录中列出的目录中的所有文章。示例:
由于我是PHP的新手,我不知道该怎么做。所有帮助表示赞赏!
答案 0 :(得分:0)
以下是您的解决方案:
$base_dir = './articles';
$filename = 'article.php';
// Listing all directories in $base_dir
$directories = scandir($base_dir);
// Looping over the directories
foreach($directories as $directory) {
if (! in_array($directory, array('.', '..'))) {
$filepath = $base_dir.'/'.$directory.'/'.$filename;
// if the file exists, we include it
if (is_file($filepath)) {
include_once($filepath);
}
}
}
答案 1 :(得分:0)
又快又脏......
$data = '';
$dir = "path_to_your_articles";
$dirHandle = opendir($dir);
$lookForThis = 'article.php';
while ($file = readdir($dirHandle)) {
if(!is_dir($file)){
if($file == $lookForThis){
$data .= $file;
}
}
}
closedir($dirHandle);
echo $data;
希望这有用......