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>&nbsp;</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>&nbsp;</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>");
    }
}
?>

 

标签:PH,HP,P自,自动,动生,生成,成月,月历,历代,代码,码
0
投稿

猜你喜欢

  • Oracle10g 安装方法

    2009-06-19 17:50:00
  • 通用的下拉菜单__用DL\\DD\\DT解决无法遮住select的问题

    2008-07-28 13:28:00
  • Python json模块与jsonpath模块区别详解

    2023-09-17 18:07:26
  • 了解WEB页面工具语言XML(四)应用分类

    2008-09-05 17:18:00
  • MS SQL Server中的CONVERT日期格式化大全

    2010-08-07 11:31:00
  • 基于网格的网页设计概念及实际应用案例

    2010-03-30 14:59:00
  • ASP程序种如何调用DLL文件

    2008-01-15 19:12:00
  • MySQL最好的优化技巧

    2009-10-27 12:05:00
  • YUI3新特性学习

    2012-04-26 16:25:20
  • EXEC(EXECUTE)函数访问INSERTED或DELETED的内部临时触发表

    2012-01-29 18:07:30
  • asp关键词屏蔽过滤函数代码

    2010-05-04 16:32:00
  • python中class(object)的含义是什么以及用法

    2023-08-07 22:00:19
  • python如何实现从视频中提取每秒图片

    2023-10-15 11:36:25
  • Python编程实现控制cmd命令行显示颜色的方法示例

    2023-07-24 05:39:45
  • Python matplotlib绘制散点图配置(万能模板案例)

    2023-08-02 23:04:18
  • 详解ASP中断开记录集的使用方法

    2008-02-13 08:35:00
  • 网站设计中的面包屑[译]

    2009-03-22 15:42:00
  • 浅谈SQL与PLSQL开发实战

    2011-05-05 08:15:00
  • Mysql数据库备份和还原常用的命令

    2011-12-01 10:41:54
  • python中matplotlib实现随鼠标滑动自动标注代码

    2023-09-02 10:49:47
  • asp之家 网络编程 m.aspxhome.com