码迷,mamicode.com
首页 > 编程语言 > 详细

日历小算法:

时间:2015-04-10 12:53:50      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

日历小算法:

<?php

echo "<table align=‘center‘ border=‘1‘>";

echo "<th style=‘background-color:green;‘>日</th>";
echo "<th style=‘background-color:green;‘>一</th>";
echo "<th style=‘background-color:green;‘>二</th>";
echo "<th style=‘background-color:green;‘>三</th>";
echo "<th style=‘background-color:green;‘>四</th>";
echo "<th style=‘background-color:green;‘>五</th>";
echo "<th style=‘background-color:green;‘>六</th>";

$year = isset($_GET[‘year‘]) ? $_GET[‘year‘] : date(‘Y‘);
$month = isset($_GET[‘month‘]) ? $_GET[‘month‘] : date(‘m‘);
$day = isset($_GET[‘day‘]) ? $_GET[‘day‘] : date(‘d‘);

$startWeek = date(‘w‘, mktime(0,0,0,$month,1,$year)); // 当月1号是星期中的第几天 param:hour minute second month day year
//w 星期中的第几天

echo "今天是$year 年-$month 月-$day 日 ";

$days = date(‘t‘, mktime(0,0,0,$month,1,$year)); // 当月有多少天

echo "<tr>";
for ($i=0; $i<$startWeek; $i++) {
echo "<td></td>"; //补几个空位
}


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

if ($day == $j) {
echo "<td style=‘background-color:red;‘>$j</td>";
} else {
echo "<td>$j</td>";
}
if ($i%7 == 0) {
echo "</tr><tr>"; //够7个换行
}

}

while($i%7 != 0) {
echo "<td></td>"; //最后补空格
$i++;
}

echo "<tr/>";
echo "</table>";

header(‘content-type:text/html;charset=utf-8‘);

 

日历小算法:

标签:

原文地址:http://www.cnblogs.com/godrain/p/4414135.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!