首页 > 开发 > PHP > 正文

PHP日历代码通用函数

2024-05-04 23:05:51
字体:
来源:转载
供稿:网友
<?php
//calendar.php
//check if the month and year values exist
if ((!$_get['month']) && (!$_get['year'])) {
   $month = date ("n");
   $year = date ("y");
} else {
   $month = $_get['month'];
   $year = $_get['year'];
}
//calculate the viewed month
$timestamp = mktime (0, 0, 0, $month, 1, $year);
$monthname = date("f", $timestamp);
//now let's create the table with the proper month
?>
<table border="1" cellpadding="3" cellspacing="0" bordercolor="#000000">
   <tr>
   <td colspan="7" class="calendartodayoff" onmouseover="this.classname='calendartodayover'" onmouseout="this.classname='calendartodayoff'">
    <span ><?php echo $monthname . " " . $year; ?></span>
   </td>
   </tr>
   <tr>
   <td class="calendartodayoff" onmouseover="this.classname='calendartodayover'" onmouseout="this.classname='calendartodayoff'">
    <span >su</span>
   </td>
   <td class="calendartodayoff" onmouseover="this.classname='calendartodayover'" onmouseout="this.classname='calendartodayoff'">
    <span >m</span>
   </td>
   <td class="calendartodayoff" onmouseover="this.classname='calendartodayover'" onmouseout="this.classname='calendartodayoff'">
    <span >tu</span>
   </td>
   <td class="calendartodayoff" onmouseover="this.classname='calendartodayover'" onmouseout="this.classname='calendartodayoff'">
    <span >w</span>
   </td>
   <td class="calendartodayoff" onmouseover="this.classname='calendartodayover'" onmouseout="this.classname='calendartodayoff'">
    <span >th</span>
   </td>
   <td class="calendartodayoff" onmouseover="this.classname='calendartodayover'" onmouseout="this.classname='calendartodayoff'">
    <span >f</span>
   </td>
   <td class="calendartodayoff" onmouseover="this.classname='calendartodayover'" onmouseout="this.classname='calendartodayoff'">
    <span >sa</span>
   </td>
   </tr>
   <?php   
    $monthstart = date("w", $timestamp);
    $lastday = date("d", mktime (0, 0, 0, $month + 1, 0, $year));
    $startdate = -$monthstart;
   
    //figure out how many rows we need.
    $numrows = ceil (((date("t",mktime (0, 0, 0, $month + 1, 0, $year)) + $monthstart) / 7));
   
    //let's make an appropriate number of rows...
    for ($k = 1; $k <= $numrows; $k++){
     ?><tr><?php
     //use 7 columns (for 7 days)...
     for ($i = 0; $i < 7; $i++){
      $startdate++;
      if (($startdate <= 0) || ($startdate > $lastday)){
       //if we have a blank day in the calendar.
       ?><td >&nbsp;</td><?php
      } else {
               
       if ($startdate == date("j") && $month == date("n") && $year == date("y")){
        ?><td class="calendartodayoff" onmouseover="this.classname='calendartodayover'; checkfortasks ('<?php echo $year . "-" . $month . "-" . $startdate; ?>',event);" onmouseout="this.classname='calendartodayoff'; hidetask();"><?php echo date ("j"); ?></td><?php
       } else {
        ?><td class="calendaroff" onmouseover="this.classname='calendarover'; checkfortasks ('<?php echo $year . "-" . $month . "-" . $startdate; ?>',event);" onmouseout="this.classname='calendaroff'; hidetask();"><?php echo $startdate; ?></td><?php
       }
      }
     }
     ?></tr><?php
    }
   ?>   
</table>
中国最大的web开发资源网站及技术社区,
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表