php-html 动态表格分行-数据结构剖析

本文介绍了一种使用PHP动态生成网页文件结构表格的方法,包括文件遍历、编码转换、目录链接创建以及表格布局优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

$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>&nbsp;</td>";
	}
}
echo '</table>';

 注:本程序动态分行理念适合所有动态语言,js,java,php···

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值