php日历表代码,PHP输出日历表代码实例

月历表

$month = array("元月","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");

$enmonth = array("元月","january" ,"february" ,"marcy" ,"april" ,"may" ,"june" ,"july" ,"august" ,"september" ,"october" ,"november" ,"december");

$week = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");

$backcolor = array("#ffc" , "#fff" , "#9f6" , "#ffc" , "#6f0" , "#6f6" , "#f90" , "#f06" , "#f00" , "#fc3" , "#ff6" , "#f99");

function printmon($year, $mon)

{

date_default_timezone_set("asia/shanghai");

global $month;

global $enmonth;

global $week;

global $backcolor;

$startdate =strtotime("1 $enmonth[$mon] $year"); //获取查询的年月

$enddate = strtotime("+1 month",$startdate); //获取下一个月的开始日期作为月历输出的截止时间

$thedate = getdate($startdate); //把日期转化为字符串格式

$color = $backcolor[$mon]; //设置月历的背景颜色

echo("

$ym = $year . "年". $month[$mon];

echo("

$ym

");

echo("

");

for ($i=0; $i<7; $i++) //输出星期几

{

echo("

");

echo("

$week[$i]

");

echo("

");

}

echo("

");

$theweek = $thedate[wday];//判断当天是星期几

for ($i=0; $i<6; $i++)

{

echo("

");

for ($j=0; $j<7; $j++)

{

echo("

");

if ($startdate < $enddate && $theweek == $j)//把日期输出到对应的星期几所在列,并注意不要超出本月日期

{

$theday = $thedate[mday];

echo("

$theday

");

$startdate = strtotime("+1 day", $startdate); //日期前移1天

$thedate = getdate($startdate);//更新日期

$theweek = ($theweek + 1) % 7;//更新星期

}

echo("

");

}

echo("

");

if ($startdate == $enddate) //如果已经输出全部日期,结束循环

{

$i = 6;

}

}

echo("

}

?>

请输入要查看的年号和月份(查询范围为1970年1月1日至2038年)

年月

$year = $_post['myyear'];

$month = $_post['mymonth'];

if (is_numeric($year) && $year >= 1970 && $year <2038)

{

if (is_numeric($month) && $month >= 1 && $month <=12)

{

printmon($year, $month);

}

else if($month != null)

{

echo("月份不对" . "
");

}

}

else if($year != null)

{

echo("年份不对" . "
");

}

?>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值