马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
学校并没有那么多的时间可以让我们在实际开发上面。日历 //calendar.php
<?
/*******************************
* 用来判别是不是闰年的函数 *
* 可以依据更庞杂的算法改善 *
*******************************/
function leap_year($year)
{
if($year% 4 == 0) // basic rule
{
return true; // is leap year
}
else
{
return false;
}
}
/*******************************
* 对一些变量停止赋值操作 *
* 出格注重对二月份的赋值 *
*******************************/
function setup()
{
global $mon_num;
$mon_num=array(31,30,31,30,31,30,31,31,30,31,30,31);
global $mon_name;
$mon_name=array("一","二","三","四",
"五","六","七","八",
"九","十","十一","十二");
if (leap_year($firstday[year])) // basic rule
{
$mon_num[1]=29; // is leap year
}
else
{
$mon_num[1]=28;
}
}
/*******************************
* 显示表格中的一格 *
* 显示的内容和色彩可变 *
*******************************/
function showline($content,$show_color)
{
$begin_mark = "<TD WIDTH=60 HEIGHT=25>";
$begin_mark =$begin_mark."<FONT COLOR=$show_color>";
$end_mark = "</FONT></TD>";
echo $begin_mark.$content.$end_mark ;
}
?>
<!--日过程序的正式入手下手-->
<html>
<head>
<title>
社区日历
</title>
<meta http-equiv=content-type content="text/html; charset=gb2312">
<head>
<body>
<?
//取得以后的日期
$firstday = getdate(mktime(0,0,0,date("m"),1,date("Y")));
setup();
//显示表格的称号
echo "<CENTER>";
echo "<TABLE BORDER=2 CELLSPACING=4>";
echo "<TH COLSPAN=7 HEIGHT=50>";
echo "<FONT COLOR=red SIZE=3 >";
echo "$firstday[year]年  ".$mon_name[$firstday[mon]-1]."月 月历";
echo "</FONT>";
echo "</TH>";
//表头
$weekDay[0] = "日";
$weekDay[1] = "一";
$weekDay[2] = "二";
$weekDay[3] = "三";
$weekDay[4] = "四";
$weekDay[5] = "五";
$weekDay[6] = "六";
echo "<TR ALIGN=\"center\" VALIGN=\"center\">";
//显示表格的第一行
for ($dayNum = 0; $dayNum < 7; ++$dayNum) {
showline($weekDay[$dayNum],"red");
}
echo"</TR>";
$toweek=$firstday[wday];//本月的第一天是礼拜几
$lastday=$mon_num[$firstday[mon]-1];//本月的最初一天是礼拜几
$day_count = 1;//以后应当显示的天数
$up_to_firstday = 1;//是不是显示到本月的第一天
for ($row = 0; $row <= ($lastday+$toweek-1)/7; ++$row)//本月有几个礼拜
{ echo "<TR ALIGN=center VALIGN=center>";
for ($col=1; $col<=7; ++$col)
{
//在第一天后面显示的都是"空"
if (($up_to_firstday <= $toweek) ||($day_count>$lastday))
{
echo "<TD> </TD>";
$up_to_firstday++;
}
else
{
//显示本月中的某一天
showline($day_count,"blue");
$day_count++;
}
}
echo "</TR>";
}
echo "</TABLE>";
echo "</CENTER>";
?>
</body>
</html>
学习数据库了,MYSQL可算是PHP的黄金搭档了,不过,虽然话是这么说,你也可能恨不得把MYSQL给生吞活剥了,因为这一行一列的东东简直让自己头晕目眩。 |