php专区

 首页 > php专区 > PHP基础 > 数组 > php查询指定目录下所有文件并保存到数组 - php数

php查询指定目录下所有文件并保存到数组 - php数

分享到:
【字体:大 中 小】
导读:
          //方法一,代码如下:$dirs=array();foreach(glob(test/*)as$d){if(is_dir($d)){$dirs[]=$d;}}print_r($dirs);//方法二,代码如下:glob(test/*,glob_onlydir);//查找目录下所有文件,代码如下:func......

php查询指定目录下所有文件并保存到数组

  1. //方法一,代码如下: 
  2. $dirs    = array(); 
  3. foreach(glob("test/*") as $d) 
  4. { 
  5.     if(is_dir($d)) 
  6.     { 
  7.         $dirs[]    = $d; 
  8.     } 
  9. } 
  10. print_r($dirs); 
  11. //方法二,代码如下: 
  12. glob("test/*", glob_onlydir) ; 
  13. //查找目录下所有文件,代码如下: 
  14. function listdir($dir){  
  15. if(is_dir($dir)){  
  16. if ($dh = opendir($dir)) {  
  17. while (($file= readdir($dh)) !== false){  
  18. if((is_dir($dir."/".$file)) && $file!="." && $file!=".."){  
  19. echo "文件名:",$file,"

    "
    ;  
  20. listdir($dir."/".$file."/");  
  21. }else{  
  22. if($file!="." && $file!=".."){  
  23. echo $file."
    "
    ;  
  24. }  
  25. }  
  26. }  
  27. closedir($dh);  
  28. }  
  29. }  
  30. }  
  31. //开始运行  
  32. listdir("e:/www.phpfensi.com/"); 
  33.  
  34. ?> 
分享到:
php过滤空数组方法与过滤数组为空的元素 ...
php过滤空数组方法与过滤数组为空的元素 php过滤空数组的方法我下面举了三个实例,一个是for,foreach,array_filter来处理,下面看实例. 方法一,利用array_filter调用我们自定的函数来过滤空值,代码如下: function clear($a)  {  return $a  "";  }    $array = arra...
判断某数组当中是否含有某字符或字符串的...
判断某数组当中是否含有某字符或字符串的函数in_array 实例代码如下: $arr_1=array(       "index/logo.png",       "www.phpfensi.com/play.png",       "movie/stop.png",       "game/war_p.png",       "game/starcaft_p.png",     ...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……