-
-
Save ClasslessAndFree/2470321 to your computer and use it in GitHub Desktop.
PHP: Recursive Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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