[php]遍历目录

2015-12-1 写技术

<?php
/**********************
* echo_tree
* echo_tree.php
* by nicholas 15-12-01
***********************/

function tree($directory) 
{ 
	$mydir = dir($directory); 
	echo '<ul>'; 
	while($file = $mydir->read()){ 
		if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")) 
		{
			echo '<li><font color="#ff00cc"><b>'.$directory.'/'.$file.'</b></font></li>'; 
			tree("$directory/$file" ); 
		}else if( ($file!=".") AND ($file!="..") ){ 
			echo '<li>'.$directory.'/'.$file.'</li>';
		}
	} 
	echo '</ul>'; 
	$mydir->close(); 
} 


echo "<h2>树形目录遍历</h2>"; 
tree("./articles"); 

?>

标签: php

发表评论:

Powered by anycle 湘ICP备15001973号-1