Skip to content

Instantly share code, notes, and snippets.

@pghoratiu
Created March 20, 2012 15:36
Show Gist options
  • Save pghoratiu/2137156 to your computer and use it in GitHub Desktop.
Save pghoratiu/2137156 to your computer and use it in GitHub Desktop.
Recursive search for files using PHP iterator
<?php
search_files('/home/gabi/test/', '.png');
function search_files($dir, $extension) {
$extension_length = strlen($extension);
$rit = new RecursiveDirectoryIterator($dir);
foreach(new RecursiveIteratorIterator($rit) as $file) {
if(strcasecmp(substr($file, -$extension_length), $extension) == 0) {
echo "$file\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment