PHP自动生成月历代码
时间:2023-11-18 09:22:52
<?php
/*
Function Written by Nelson Neoh @3/2004.
For those who wants to utilize this code, please do not remove this remark.
If you have done any enhancement to this code, please post the copy at http://www.dev-club.com PHP board. Thank you.
Function usage: calendar(Month,Year)
*/
function calendar($MM,$YYYY){
if($MM=="") $MM = date("m");
if($YYYY=="") $YYYY = date("Y");
if(checkdate($MM,1,$YYYY)){
$stringDate = strftime("%d %b %Y",mktime (0,0,0,$MM,1,$YYYY));
$days = strftime("%d",mktime (0,0,0,$MM+1,0,$YYYY));
$firstDay = strftime("%w",mktime (0,0,0,$MM,1,$YYYY));
$lastDay = strftime("%w",mktime (0,0,0,$MM,$days,$YYYY));
$printDays = $days;
$preMonth = strftime("%m",mktime (0,0,0,$MM-1,1,$YYYY));
$preYear = strftime("%Y",mktime (0,0,0,$MM-1,1,$YYYY));
$nextMonth = strftime("%m",mktime (0,0,0,$MM+1,1,$YYYY));
$nextYear = strftime("%Y",mktime (0,0,0,$MM+1,1,$YYYY));
print("<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\">");
print("<tr><th valign=\"top\"><a href=\"".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$preMonth."&YY=".$preYear."\">P</a></th>");
print("<th colspan=\"5\" valign=\"top\">".strftime("%b %Y",mktime (0,0,0,$MM,1,$YYYY))."</th>");
print("<th valign=\"top\"><a href=\"".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$nextMonth."&YY=".$nextYear."\">N</a></th></tr>");
print("<tr style=\"font-family: Verdana; font-size:x-small\">");
print("<th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>");
$currentDays = 1;
for($a=1;$a<=5;$a++){
print("<tr align=\"left\" valign=\"top\" style=\"font-family: Verdana; font-size:x-small\">");
$diffDays = $firstDay-$lastDay;
if($firstDay>$lastDay && $currentDays ==1 && ($diffDays<>1)){
for($x=$lastDay;$x>=0;$x--){
$printDays = $days-$x;
print("<td>$printDays</td>");
}
for($z=1;$z<$firstDay-$lastDay;$z++){
print("<td> </td>");
}
for($y=$firstDay;$y<7;$y++){
print("<td>$currentDays</td>");
$currentDays++;
}
} elseif($firstDay!=0 && $currentDays==1){
for($z=1;$z<=$firstDay;$z++){
print("<td> </td>");
}
for($y=$firstDay;$y<7;$y++){
print("<td>$currentDays</td>");
$currentDays++;
}
} else {
for($u=1;$u<=7 && $currentDays<=$days;$u++){
print("<td>$currentDays</td>");
$currentDays++;
}
}
print("</tr>");
}
print("</table>");
}
}
?>
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Oracle10g 安装方法
通用的下拉菜单__用DL\\DD\\DT解决无法遮住select的问题
Python json模块与jsonpath模块区别详解
了解WEB页面工具语言XML(四)应用分类
MS SQL Server中的CONVERT日期格式化大全
基于网格的网页设计概念及实际应用案例
![](https://img.aspxhome.com/file/UploadPic/20103/30/1052570-42s.jpg)
ASP程序种如何调用DLL文件
MySQL最好的优化技巧
YUI3新特性学习
EXEC(EXECUTE)函数访问INSERTED或DELETED的内部临时触发表
asp关键词屏蔽过滤函数代码
python中class(object)的含义是什么以及用法
python如何实现从视频中提取每秒图片
Python编程实现控制cmd命令行显示颜色的方法示例
![](https://img.aspxhome.com/file/2023/0/60940_0s.jpg)
Python matplotlib绘制散点图配置(万能模板案例)
![](https://img.aspxhome.com/file/2023/9/61989_0s.png)
详解ASP中断开记录集的使用方法
网站设计中的面包屑[译]
![](https://img.aspxhome.com/file/UploadPic/20093/22/01-47s.jpg)
浅谈SQL与PLSQL开发实战
Mysql数据库备份和还原常用的命令
python中matplotlib实现随鼠标滑动自动标注代码
![](https://img.aspxhome.com/file/2023/7/62867_0s.gif)