php递归查找指定目录下及子文件名称是否包含【中文】【 空格】【 括号】

 1 //php递归查找该目录下及子文件名称是否包含中文空格括号
 2 function searchDir($path,&$data){
 3     if(is_dir($path)){
 4         $dp=dir($path);
 5         while($file=$dp->read()){
 6             if($file!='.'&& $file!='..'){
 7                 searchDir($path.'/'.$file,$data);
 8             }
 9         }
10         $dp->close();
11     }
12     if(is_file($path)){
13         $reg_chinese = '/[^\x00-\x80]/';    //匹配中文
14         $reg_brackets = '/\( [^\)]+? \)/x';  //匹配括号
15         $reg_space = "/\s/";           //匹配空格
16         if(preg_match($reg_chinese,$path) || preg_match($reg_brackets,$path) || preg_match($reg_space, $path)){
17             $data[]=$path;
18         }
19     }
20 }
21 
22 function getDir($dir){
23     $data=array();
24     searchDir($dir,$data);
25     return   $data;
26 }
27 echo '<pre>';
28 print_r(getDir("D:\project\\"));//指定目录

 

posted @ 2017-08-23 18:42  YouWong  阅读(252)  评论(0编辑  收藏  举报