专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » php代码生成器:PHP自动生成月历代码 »正文

php代码生成器:PHP自动生成月历代码

来源: 发布时间:星期一, 2009年1月12日 浏览:10次 评论: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){
  ($MM"") $MM = date("m");
  ($YYYY"") $YYYY = date("Y");
  (checkdate($MM,1,$YYYY)){
    $Date = 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));
    $prDays = $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));
    pr("<table border="1" cellpadding="1" cellspacing="1">");
    pr("<tr><th valign="top"><a href="".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$preMonth."&YY=".$preYear."">P</a></th>");
    pr("<th colspan="5" valign="top">".strftime("%b %Y",mktime (0,0,0,$MM,1,$YYYY))."</th>");
    pr("<th valign="top"><a href="".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$nextMonth."&YY=".$nextYear."">N</a></th></tr>");
    pr("<tr style="font-family: Verdana; font-size:x-small">");
    pr("<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){
      pr("<tr align="left" valign="top" style="font-family: Verdana; font-size:x-small">");
      $dfDays = $firstDay-$lastDay;
      ($firstDay>$lastDay && $currentDays 1 && ($dfDays<>1)){
        for($x=$lastDay;$x>=0;$x--){
          $prDays = $days-$x;
          pr("<td>$prDays</td>");
        }
        for($z=1;$z<$firstDay-$lastDay;$z){
          pr("<td></td>");
        }
        for($y=$firstDay;$y<7;$y){
          pr("<td>$currentDays</td>");
          $currentDays;
        }
      } ($firstDay!=0 && $currentDays1){
        for($z=1;$z<=$firstDay;$z){
          pr("<td></td>");
        }
        for($y=$firstDay;$y<7;$y){
          pr("<td>$currentDays</td>");
          $currentDays;
        }
      } {
        for($u=1;$u<=7 && $currentDays<=$days;$u){
          pr("<td>$currentDays</td>");
          $currentDays;
        }
      }
      pr("</tr>");
    }
    pr("</table>");
  }
}
?>


0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: