Home > Backend Development > PHP Tutorial > 求段php代码 如何读取出 指定目录下 的文件

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:28:33
Original
862 people have browsed it

比如 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*');
Copy after login

<?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);?>
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template