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!?

Recommended Answers

All 4 Replies

Member Avatar for diafol
$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.

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

fixed it like this:

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

Member Avatar for diafol

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".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.