Home  >  Article  >  php教程  >  利用PHP内置dir类实现目录遍历显示

利用PHP内置dir类实现目录遍历显示

PHP中文网
PHP中文网Original
2016-05-25 17:09:161079browse

php代码

function listDir( $dir )
{
	$dirObj = dir($dir);
	$ul = "";
	
	while ($file = $dirObj->read())
	{
		if ( is_dir($dir .'/'. $file) )
		{
			$ul .= "" .$file. "";
			$ul .= listDir( $dir .'/'. $file );
		}
		else	$ul .= "{$file}";
	}
	$ul .= "";
	$dirObj->close();
	return $ul;
}

echo listDir('./demo');

Statement:
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