首页 > 开发 > PHP > 正文

自动生成月历代码

2024-05-04 22:59:40
字体:
来源:转载
供稿:网友
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  • <?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>");
        }
    }
    ?>

     

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表