function &search($pattern, $directory, $type = 'php', $fullpath = true, $match = 'files')
{
$matches = array();
list($directories, $files) = File_Find::maptree($directory);
switch ($match) {
case 'directories':
$data = $directories;
break;
case 'both':
$data = array_merge($directories, $files);
break;
case 'files':
default:
$data = $files;
}
unset($files, $directories);
$match_function = File_Find::_determineRegex($pattern, $type);
reset($data);
// check if empty string given (ok for 'shell' method, but bad for others)
if ($pattern || $type != 'php' && $type != 'perl') {
while (list(, $entry) = each($data)) {
if ($match_function($pattern, $fullpath ? $entry : basename($entry))) {
$matches[] = $entry;
}
}
}
sort($matches);
return $matches;
}