>백엔드 개발 >PHP 튜토리얼 >求段php代码 如何读取出 指定目录下 的文件

求段php代码 如何读取出 指定目录下 的文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB원래의
2016-06-23 13:28:33876검색

比如 temlate目录下有很多文件哈
有a.html b.html list_111.html list.html list222.html
我想读取出

以list开头的文件

结果有 list_111.html list.html list222.html


回复讨论(解决方案)

你可以考虑先使用opendir()打开文件夹,再使用readdir()函数遍历文件夹, readdir()函数可以返回目录下的文件名。接着用substr()函数,应该可以完成你要的功能。

$files = glob('temlate/list*');

<?php$path = dirname(__FILE__); // 这里填写要搜寻的目录$result = array();if($handle = opendir($path)){      while(($file=readdir($handle))!==false){          if($file!='.' && $file!='..'){          	if(strtolower(substr($file,0,4))=='list'){        		array_push($result, $file);        	}        }      }      closedir($handle);  }  print_r($result);?>

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.