利用PHP实现日历表
<?php
header(content-type:"text/html;charset=utf-8");
//设定变量假设1个月为31天
$days=31;
$k=0;
echo "<table width=‘700px‘ border=‘1px‘ align=‘center‘>";
echo "<caption>日历表</caption>";
for($i=1;$i<=$days;){
//记录循环次数,隔行换色
$k++;
if($k%2==0){
echo "<tr style=‘background:#ccc‘>";
}else{
echo "<tr style=‘background:#faa‘>";
}
for($j=1;$j<=7;$j++){
if($i>$days){
echo "<td> </td>";
}else{
echo "<td>{$i}</td>";
}
$i++;
}
echo "</tr>";
}
echo "</table>";
时间: 2024-11-01 11:02:31