dynamic - PHP incomplete code - scan dir, include only if name starts or end with x -


i posted question before yet limited mix code without getting errors.. i'm rather new php :(

( dirs named in series "id_1_1" , "id_1_2", "id_1_3" , "id_2_1" , "id_2_2", "id_2_3" etc.)

i have code, scan directory files , include same known named file each of existing folders.. problem want modify bit code include directories names:

  1. ends "_1"
  2. starts "id_1_"

i want create page load dirs ends "_1" , file load dirs starts "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 $file) {     if($file->isdir()) {         $includes[] = strtoupper($file . '/template.php');     } }  $includes = array_reverse($includes);  foreach($includes $file){    include $file; }  include_once "$root/content/common/footer.php";  ?> 

many thanks!

foreach($iterator $file) {     if($file->isdir()) {         // getfilename() gives directory name, when it's um, directory.         $dirname = $file->->getfilename();         if (substr($dirname, 0, 5) === 'id_1_') {             $includes[] = strtoupper($file . '/template.php');         }     } } 

there's other ways this, tried add simple functions , logic, in hopes understand it.

ends with like

if (substr($dirname, -2) === '_1') 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -