php class F_FileIterator extends FilterIterator private ext private it

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
class F_FileIterator extends FilterIterator {
private $ext;
private $it;
function __construct(DirectoryIterator $it, $ext) {
parent::__construct($it);
$this->it=$it;
$this->ext=$ext;
}
function accept() {
$ext=pathinfo($this->current(),PATHINFO_EXTENSION);
return ($ext==$this->ext) ? true : false;
}
}
$d=new F_FileIterator(new DirectoryIterator('.'), 'php');
foreach ($d as $v) {
echo "$v<br />\n";
}
?>