月历1997年php代码_PHP实现的简单日历代码

//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 = "

";

$begin_mark =$begin_mark."";

$end_mark = "

";

echo $begin_mark.$content.$end_mark ;

}

?>

社区日历

//获得当前的日期

$firstday  = getdate(mktime(0,0,0,date("m"),1,date("Y")));

setup();

//显示表格的名称

echo "

";

echo "

echo "

";

echo "";

echo "$firstday[year]年 &nbsp".$mon_name[$firstday[mon]-1]."月&nbsp月历";

echo "";

echo "

";

//表头

$weekDay[0] = "日";

$weekDay[1] = "一";

$weekDay[2] = "二";

$weekDay[3] = "三";

$weekDay[4] = "四";

$weekDay[5] = "五";

$weekDay[6] = "六";

echo "

";

//显示表格的第一行

for ($dayNum = 0; $dayNum < 7; ++$dayNum) {

showline($weekDay[$dayNum],"red");

}

echo"

";

$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 "

";

for ($col=1; $col<=7; ++$col)

{

//在第一天前面显示的都是"空"

if (($up_to_firstday <= $toweek) ||($day_count>$lastday))

{

echo "

&nbsp";

$up_to_firstday++;

}

else

{

//显示本月中的某一天

showline($day_count,"blue");

$day_count++;

}

}

echo "

";

}

echo "

";

echo "

";

?>

原文链接:

http://blog.csdn.net/newhappy2008/article/details/1427990

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值