PHP incomplete code - scan dir, include only if name starts or end with x
Posted
by Adrian M.
on Stack Overflow
See other posts from Stack Overflow
or by Adrian M.
Published on 2010-04-28T14:15:41Z
Indexed on
2010/04/28
18:27 UTC
Read the original article
Hit count: 374
I posted a question before but I am yet limited to mix the code without getting errors.. I'm rather new to php :(
( the dirs are named in series like this "id_1_1" , "id_1_2", "id_1_3" and "id_2_1" , "id_2_2", "id_2_3" etc.)
I have this code, that will scan a directory for all the files and then include a same known named file for each of the existing folders.. the problem is I want to modify a bit the code to only include certain directories which their names:
- ends with "_1"
- starts with "id_1_"
I want to create a page that will load only the dirs that ends with "_1" and another file that will load only dirs that starts with "id_1_"..
<?php
include_once "$root/content/common/header.php";
include_once "$root/content/common/header_bc.php";
include_once "$root/content/" . $page_file . "/content.php";
$page_path = ("$root/content/" . $page_file);
$includes = array();
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($page_path),
RecursiveIteratorIterator::SELF_FIRST);
foreach($iterator as $file) {
if($file->isDir()) {
$includes[] = strtoupper($file . '/template.php');
}
}
$includes = array_reverse($includes);
foreach($includes as $file){
include $file;
}
include_once "$root/content/common/footer.php";
?>
Many Thanks!
© Stack Overflow or respective owner