0

here is my little code:

<?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++;
 } 
} 
?>

how can i add more file extensions to this code to be excluded!?

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by diafol
0
$ext_array = array(".htm", ".php", ".asp", ".stml",".html",".shtml",".cfg");
$dir1 = $filex.'/88x31'; 
$filecount1 = 0; 
$d1 = dir($dir1); 
 
while ($f1 = $d1->read()) { 
  if (in_array($f1, $ext_array)) {
    continue;
  }else{
    if(($f1!= '.') && ($f1!= '..')) { 
       if(!is_dir($f1)) $filecount1++;
    } 
  }
}

How's that? Off the top of my head, so not tested. I worked it around your current code, so should work without too much messing about.

Have a look at the glob() function - a bit awkward as there sin't much info on it. The GLOB_BRACE flag could be useful.

Edited by diafol: n/a

0

it says:
Warning: strstr() [function.strstr]: needle is not a string or an integer in E:\xampp\htdocs\max\count.php on line 9

0

fixed it like this:

if(strstr( $f1, '.htm' )) continue;
if(strstr( $f1, '.php' )) continue;
if(strstr( $f1, '_url' )) continue;

0

it says:
Warning: strstr() [function.strstr]: needle is not a string or an integer in E:\xampp\htdocs\max\count.php on line 9

I don't understand. My idea didn't use strstr.

Sorry, noticed, mine won't work anyway coz it tests the whole file name against the extensions in the list.

$ext_array = array(".htm", ".php", ".asp", ".stml",".html",".shtml",".cfg"); //list of extensions not required
$dir1 = $filex.'/88x31'; 
$filecount1 = 0; 
$d1 = dir($dir1); 
 
while ($f1 = $d1->read()) { 
  $fext = substr($f1,strrpos($f1,".")); //gets the file extension
  if (in_array($fext, $ext_array)) { //check for file extension in list
    continue;
  }else{
    if(($f1!= '.') && ($f1!= '..')) { 
       if(!is_dir($f1)) $filecount1++;
    } 
  }
}

Think that should work. So although it might look more complicated, the ease of use comes from the ability to just add/edit the $ext_array. However it won't check for "_url".

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.