//SPL自定义文件过滤器 <?php /** * 自定义文件过滤迭代器 * @author wolf [Email: 116311316@qq.com] * */ class FileExtensionFinder extends FilterIterator { protected $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()); $basename = $pathInfo['basename']; $pre=$this->predicate; if(strpos($basename,$pre)!==false){ return $basename ; } } } $it = new FileExtensionFinder(HTML, 'show'); foreach ($it as $entry) { @unlink($entry); echo $entry . "删除成功<br>"; } @unlink(HTML."index.html');