文件遍历函数:read_directory
1 function read_directory($dir,$floor=0) 2 { 3 4 if(!is_dir($dir)) 5 { 6 return false; 7 } 8 $handir=opendir($dir); 9 while(($row=@readdir($handir))!==false) 10 { 11 12 $floor?$line=$floor-20:$floor=0; 13 if($row!='.'&&$row!='..') 14 { 15 16 if(is_file($dir.'/'.$row)) 17 { 18 if($floor>20) 19 { 20 echo "<span style='display:block;float:left;".$floor."px;'><div style='".$line."px;height:20px;border-right:1px solid #000;float:left;'></div>--</span>"; 21 echo "文件:".$dir.'/'.$row."<br/>"; 22 } 23 else 24 { 25 echo "文件:".$dir.'/'.$row."<br/>"; 26 } 27 } 28 else 29 { 30 31 if($floor>20) 32 { 33 echo "<span style='display:block;float:left;".$floor."px;'><div style='".$line."px;height:20px;border-right:1px solid #000;float:left;'></div>--</span>"; 34 echo "目录:".$row."<br>"; 35 $func=__FUNCTION__; 36 $endfloor=$floor+20; 37 $func($dir.'/'.$row,$endfloor); 38 } 39 else 40 { 41 42 echo "目录:".$row."<br>"; 43 $func=__FUNCTION__; 44 $endfloor=$floor+20; 45 $func($dir.'/'.$row,$endfloor); 46 } 47 } 48 } 49 } 50 }
内容替换函数:rep
1 function rep($reg){ 2 $redata = [ 3 '/css//' => "__CS__/", 4 '/js//' => "__JS__/", 5 '/images//' => "__IMG__/", 6 '/picture//' => "__PIC__/", 7 '/gif//' => "__GIF__/" 8 ]; 9 $content=file_get_contents($reg); 10 $arr=[]; 11 foreach($redata as $pat=>$text) 12 { 13 preg_match_all($pat,$content,$arr); 14 var_dump($arr); 15 foreach($arr[0] as $key=>$val) 16 { 17 $content = preg_replace($pat,$text,$content); 18 } 19 } 20 21 file_put_contents($reg,$content); 22 }