實例代碼:
<?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/>"; } ?>
版權聲明:本文為博主原創文章,未經博主允許不得轉載。
以上就介紹了php使用spl庫遍歷文件,包含了方面的內容,希望對PHP教程有興趣的朋友有幫助。