【发布时间】:2012-08-02 07:43:07
【问题描述】:
这是我的混合 PHP 和 HTML 的代码。 (它显示 4X4 表格。)
如何让这段代码更具可读性?
如果你改变 HTML 缩进,你应该改变整个 HTML。 (此代码是整个源代码的一部分。)
你对我有什么想法吗?请告诉我。塔。
<!-- GALLERY BEGIN -->
<tr>
<td style="padding-top:5px;"><table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr>
<?php
$ii = 0;
$aRows = getArticle('board_table', $DB_CONNECT, 8);
foreach ($aRows as $iidx => $aRow) :
$ii++;
$U = getUpfiles('upload_table',$aRow[uid],'');
$pic = getImage($U);
?>
<td width="75"><table width="60" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><a href="<?=$aRow[link]?>"><img src="<?=$pic?>"/></a></td>
</tr>
<tr>
<td align="center"><?=getStrCut($aRow[subject], 8, '..')?></td>
</tr>
</table></td>
<?php if($ii%4==0): ?>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr>
<?php endif; ?>
<?php endforeach; ?>
</tr>
</table></td>
</tr>
<!-- END BEGIN -->
【问题讨论】:
-
我会首先为您的循环使用大括号 ({}) 而不是类似 BASIC 的语法。这将使阅读和缩进(IMO)更容易。我还建议在代码块之间留出额外的间距。
标签: php html coding-style indentation