首页 > 技术文章 > while实现日历

qiaozhiming123 2020-04-22 17:27 原文

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
</head>
<body>
<center>
<h2>日历表格</h2>
<hr>
<table width='1000px' border='1px' cellspacing='0'>
<tr>
<th>周日</th>
<th>周一</th>
<th>周二</th>
<th>周三</th>
<th>周四</th>
<th>周五</th>
<th>周六</th>
</tr>
<?php
$days=31;

for($i=1;$i<=$days;){

if($i%2==1){
echo '<tr style="background:#aaf">';
}else{
echo '<tr>';
}

for($j=0;$j<7;$j++,$i++){
if($i>$days){
echo '<td>&nbsp;</td>';
}else{
echo "<td>{$i}</td>";
}
}
echo '</tr>';
}
?>
</table>
</center>
</body>
</html>

推荐阅读