Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 752139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:44:48+00:00 2026-05-14T14:44:48+00:00

I posted a question before but I am yet limited to mix the code

  • 0

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:

  1. ends with “_1”
  2. 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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:44:49+00:00Added an answer on May 14, 2026 at 2:44 pm
    foreach($iterator as $file) {
        if($file->isDir()) {
            // getFilename() actually gives the directory name, when it's um, a directory.
            $dirName = $file->->getFilename();
            if (substr($dirName, 0, 5) === 'id_1_') {
                $includes[] = strtoupper($file . '/template.php');
            }
        }
    }
    

    There’s other ways to do this, but I tried to only add simple functions and logic, in hopes you will understand it.

    Ends with would look like

    if (substr($dirName, -2) === '_1')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been posted before... but I haven't found any answer
I've seen this question posted here before but I want to get a final
Before I posted this question, I already looked this , but I couldn't get
I know i have posted a similar question before but i am not able
I've actually posted this question before, but it hasn't been answered. Maybe I wasn't
(I've posted a similar question before but now it is more targeted..) I am
I have posted a similar question before why my local object destroyed twice? but
First off I apologize... I have posted this question before, but I did a
I posted this question here before but there were no responses. I may have
I posted this basic question before, but didn't get an answer I could work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.