php使用spl库遍历文件

来源:互联网 发布:win10用的c语言编译器 编辑:程序博客网 时间:2024/04/29 12:59

实例代码:

<?phpclass ExtentionFinder extends FilterIterator{public $predicate, $path;public function __construct($path, $predicate){$this->predicate = $predicate;$this->path = $path;$it = new RecursiveDirectoryIterator($path);$flatIterator = new RecursiveIteratorIterator($it);parent::__construct($flatIterator);}public function accept(){$pathInfo = pathinfo($this->current());$extension = $pathInfo['extension'];return ($extension == $this->predicate);}}?><?php$it = new ExtentionFinder('./', 'php');foreach($it as $value){echo $value."<br/>";}?>


0 0
原创粉丝点击