note 24025 added to function.stristr

From: Date: Sun, 04 Aug 2002 15:52:52 +0000
Subject: note 24025 added to function.stristr
Groups: php.notes 
Request: Send a blank email to php-notes+get-34264@lists.php.net to get a copy of this message
Use this function to return the number of files matching a certain type (extention) in a given folder: Using the previous code in the function above, file extentions like .ext.inc.php will be counted as .php files usage: returns false if dir doesnt exist or returns the number of files counted DO NOT add '.' to extention you are searching for. example usage: $result = CountFiles("./images", "jpg"); if($result === false) die("dir does not exist!"); function CountFiles($dir, $type) { if(!($dh =@opendir("$dir"))) return false; // directory does not exist // read the directory contents searching for "type" files // and count how many are found: $files = 0; while ( ! ( ($fn = readdir($dh)) === false ) ) { $f = strrev($fn); $ext = substr($f, 0, strpos($f,".")); $f_ext = strrev($ext); if(( strcasecmp($f_ext, $type) == 0 )) $files++; } closedir($dh); return $files; } -- http://www.php.net/manual/en/function.stristr.php http://master.php.net/manage/user-notes.php?action=edit+24025 http://master.php.net/manage/user-notes.php?action=delete+24025 http://master.php.net/manage/user-notes.php?action=reject+24025

« previous php.notes (#34264) next »