What I did was use the substr function. It looks like this:
$handle=opendir($sPath);
while ($filename = readdir($handle)) {
if(substr($filename,-4) == "$ext"){
echo $filename;
}
}
This will print out all files with the extensions that you specify. One thing you need to know, the negative four onle takes the last four characters of a filename and looks at them. In onther words, if you have a file with a .command extension, it will only look at the mand. Hope this helps!