PHP自动生成月历代码

所属分类: 网络编程 / PHP编程 阅读数: 1847
收藏 0 赞 0 分享

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

 

更多精彩内容其他人还在看

浅谈php中curl、fsockopen的应用

下面小编就为大家带来一篇浅谈php中curl、fsockopen的应用。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

php异步:在php中使用fsockopen curl实现类似异步处理的功能方法

下面小编就为大家带来一篇php异步:在php中使用fsockopen curl实现类似异步处理的功能方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

PHP页面跳转实现延时跳转的方法

下面小编就为大家带来一篇PHP页面跳转实现延时跳转的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

PHP获取页面执行时间的方法(推荐)

这篇文章主要介绍了PHP获取页面执行时间的方法(推荐)的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

PHP中SQL查询语句的id=%d解释(推荐)

很多朋友不清楚php中sql查询语句的id=%d的意思,今天小编通过本文给大家详细介绍下PHP中SQL查询语句的id=%d解释,需要的朋友参考下吧
收藏 0 赞 0 分享

PHP与SQL语句常用大全

很多朋友不清楚php中sql查询语句的id=%d的意思,今天小编通过本文给大家详细介绍下PHP中SQL查询语句的id=%d解释,需要的朋友参考下吧
收藏 0 赞 0 分享

Zend Framework分发器用法示例

这篇文章主要介绍了Zend Framework分发器用法,结合实例形式分析了Zend Framework分发器的功能、定义及简单使用方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Zend Framework路由器用法实例详解

这篇文章主要介绍了Zend Framework路由器用法,结合实例形式分析了Zend Framework路由器的功能、定义与基本使用方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Zend Framework前端控制器用法示例

这篇文章主要介绍了Zend Framework前端控制器用法,结合实例形式分析了Zend Framework前端控制器的常用方法与相关使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

Zend Framework入门应用实例详解

这篇文章主要介绍了Zend Framework入门应用,结合实例形式详细讲述了Zend Framework应用的创建步骤、相关命令、控制器及视图文件代码实现技巧,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多