您的位置:首页 > 编程语言 > PHP开发

php使用spl库遍历文件

2015-09-11 14:17 465 查看
实例代码:

<?php
class 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/>";
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: