class="php" name="code">$files = scandir('.'); echo '<table align="center" border="1" cellpadding="5" cellspacing="0" width="800" style="min-width:444px;">'; $counter = 1; $each_columns = 4; foreach($files as $file_num => $file) { if($file_num > 1){ $file = iconv("GBK","UTF-8",$file); //或者 iconv("gb2312","UTF-8",$value); if(is_dir($file)){ $file = '<a href="'.$file.'">'.$file.'</a>'; if($counter % $each_columns == 1) { echo '<tr>'; } echo '<td>'.$counter.$file.'</td>'; if($counter % $each_columns == 0){ echo '</tr>'; } $counter++; } } } $counter = $counter-1; if($counter % $each_columns != 0){ for($i = 0; $i < ($each_columns-($counter)%$each_columns); $i++){ echo "<td> </td>"; } } echo '</table>';
?注:本程序动态分行理念适合所有动态语言,js,java,php···