Home > Backend Development > PHP Tutorial > php uses spl library to traverse files

php uses spl library to traverse files

WBOY
Release: 2016-07-29 09:15:34
Original
1026 people have browsed it

Example code:

<?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(&#39;./&#39;, &#39;php&#39;);
	foreach($it as $value)
	{
		echo $value."<br/>";
	}
?>
Copy after login

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces how PHP uses the spl library to traverse files, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template