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 8087953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:56:33+00:00 2026-06-05T18:56:33+00:00

<?php // open the current directory $dhandle = opendir(‘.’); // define an array to

  • 0
<?php
// open the current directory
$dhandle = opendir('.');
// define an array to hold the files
$files = array();

if ($dhandle) {
   // loop through all of the files
   while (false !== ($fname = readdir($dhandle))) {

      if (($fname != 'other') && ($fname != 'dd') && ($fname != 'index.htm') && ($fname != 'torcache.php')&& ($fname != 'error_log') && 
          ($fname != basename($_SERVER['PHP_SELF']))) {
          // store the filename
          $files[] = (is_dir( "./$fname" )) ? "(Dir) {$fname}" : $fname;
      }
   }
   // close the directory
   closedir($dhandle);
}

what i would like to do is if the file starts with ‘other’ or ‘dd’ then to not include it in the loop $files; short of naming the whole filename in the !=, what can i do to exclude these files?

  • 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-06-05T18:56:35+00:00Added an answer on June 5, 2026 at 6:56 pm

    Add this to your checks:

    (substr($fname, 0, 5) != 'other') && (substr($fname, 0, 2) != 'dd')
    

    See PHP substr. It takes a string and returns a substring starting at the first number given (0 means start of string) and with a length given by the second number (5 for “other” and 2 for “dd”).

    So your complete statement would be:

    if (
        (substr($fname, 0, 5) != 'other') &&
        (substr($fname, 0, 2) != 'dd') &&
        ($fname != 'index.htm') &&
        ($fname != 'torcache.php') &&
        ($fname != 'error_log') &&
        ($fname != basename($_SERVER['PHP_SELF']))
    ) { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a keyboard shortcut or plugin to open PHP required or included files
I'm using Eclipse, and after a restart, I suddenly can't open PHP files. When
current.php is page which we open in browser. other_1.php and other_2.php are pages, which
Possible Duplicate: What is the difference between the PHP open tags <?= and <?php/<??
I'm working on an open source PHP application. The application may need to connect
My goal here is to open temp.php, explode by ### (line terminator), then by
I'd like to fork an open-source php-library. It has its own license, in which
I want to use the sharer.php popup to open the share dialog, but would
When I open a MySQL connection in PHP with just PHP's built-in MySQL functions,
I'm trying to edit my sidebar.php file in my current them WP is using

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.