[转]搜索文件夹中的文件
<?php
function search ( $target , $directory ) {
if ( is_dir ( $directory ) ) {
$direc = opendir ( $directory ) ;
while ( false !== ( $file = readdir ( $direc ) ) ) {
if ( $file != "." && $file != ".." ) {
if ( is_file ( $directory . "/" . $file ) ) {
if ( preg_match ( "/ $target /i" , $file ) ) {
echo "<a href=" $directory / $file "> $file </a> <br/>
" ;
}
} else if ( is_dir ( $directory . "/" . $file ) ) {
search ( $target , $directory . "/" . $file ) ;
}
}
}
closedir ( $direc ) ;
}
return ;
}
// how to use
search ( "ind" , "./" ) ;
?>