exclude more file extensions

  • seularts
  • Graduate
  • Graduate
  • User avatar
  • Posts: 153
  • Loc: Romania

Post 3+ Months Ago

here is my little code:

Code: [ Select ]
<?php    
$dir1 = $filex.'/88x31';
$filecount1 = 0;
$d1 = dir($dir1);

while ($f1 = $d1->read()) {
if(strstr( $f1, '.htm' )) continue;
if(($f1!= '.') && ($f1!= '..')) {
if(!is_dir($f1)) $filecount1++;
}
}
?>
  1. <?php    
  2. $dir1 = $filex.'/88x31';
  3. $filecount1 = 0;
  4. $d1 = dir($dir1);
  5. while ($f1 = $d1->read()) {
  6. if(strstr( $f1, '.htm' )) continue;
  7. if(($f1!= '.') && ($f1!= '..')) {
  8. if(!is_dir($f1)) $filecount1++;
  9. }
  10. }
  11. ?>


how can i add more file extensions to this code to be excluded!?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Sledgehammer
  • Genius
  • User avatar
  • Posts: 13496
  • Loc: Florida

Post 3+ Months Ago

Create an associative array with the to-be-skipped extensions used as keys

PHP Code: [ Select ]
$skip = array(
  '.htm'  => true,
  '.xml'  => true
);
  1. $skip = array(
  2.   '.htm'  => true,
  3.   '.xml'  => true
  4. );


and check if that key is set inside the loop. You can use isset() instead of empty, but using empty() will let you toggle the values in your array instead of having to remove them.

PHP Code: [ Select ]
if( ! empty($skip[$file_extension])) continue;


Doing it this way will require you to pull the extension off the filename, but you'll avoid using two loops and a single call to empty() should work faster than a call to in_array().

empty() is like using a phone book to see if there is a "Bob" listed and then calling the listed number to see if he's home, whereas using in_array() would be like starting at "000-0000" and calling every number to see if "Bob" answers.
  • seularts
  • Graduate
  • Graduate
  • User avatar
  • Posts: 153
  • Loc: Romania

Post 3+ Months Ago

thanks:)

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 75 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.