1) How to count how many files there are in this directory
2) How to count how many php files there are in this directory
3) How to count how many non-txt files there are in this directory
$arr = scandir($ dir);
$all = count($arr)-2;//The total number of all files except ./ and ../
$php = count(preg_grep("/.php$/", $arr));
$ txt0 = $all - count(preg_grep("/.txt$/", $arr));
echo 'There are '.$all.' files, php files '.$php.', non-txt files'. $txt0.'piece';