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

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

首页 »PHP教程 » 日历代码:PHP实现的简单日历代码 »正文

日历代码:PHP实现的简单日历代码

来源: 发布时间:星期一, 2009年1月12日 浏览:41次 评论:0
//calendar.php
<?                                     
/*******************************                     
 *  用来判断是否闰年  *                     
 *  可以根据更复杂算法改进 *                     
 *******************************/                     
 function leap_year($year)                        
  {                                 
   ($year% 4 0) // basic rule                   
      {                               
       true; // is leap year                 
      }                               
                                   
   {                                  
    false;                           
   }                                  
  }                                   
/*******************************                     
 *  对些变量进行赋值操作  *                     
 *  特别注意对 2月份赋值  *                     
 *******************************/                     
 function up                             
  {                                    
  global $mon_num;                           
  $mon_num=.gif' />(31,30,31,30,31,30,31,31,30,31,30,31);         
   global $mon_name;                           
  $mon_name=.gif' />(""," 2"," 3"," 4",                 
         " 5"," 6"," 7"," 8",                  
         " 9","十","十","十 2");               
  (leap_year($firstday[year])) // basic rule             
     {                                
      $mon_num[1]=29; // is leap year                
     }                                
                                   
  {                                   
   $mon_num[1]=28;                           
  }                                   
  }                                    
/*******************************                     
 *  显示表格中格     *                     
 *  显示内容和颜色可变   *                     
 *******************************/                     
    function showline($content,$show_color)              
    {                                 
     $begin_mark = "<TD WIDTH=60 HEIGHT=25>";             
 $begin_mark =$begin_mark."<FONT COLOR=$show_color>";          
 $end_mark = "</FONT></TD>";                      
     echo $begin_mark.$content.$end_mark ;               
    }                                 
?>                                     
<!--日历正式开始-->                         
<html>                                   
<head>                                   
<title>                                  
社区日历                                  
</title>                                  
<meta http-equiv=content-type content="text/html; char=gb2312">     
<head>                                   
<body>                                   
<?                                     
  //获得当前日期                            
  $firstday = getdate(mktime(0,0,0,date("m"),1,date("Y")));       
  up;                                
    //显示表格名称                          
echo "<CENTER>";                            
echo "<TABLE BORDER=2 CELLSPACING=4>";                 
echo "<TH COLSPAN=7 HEIGHT=50>";                    
echo "<FONT COLOR=red SIZE=3 >";                    
echo "$firstday[year]年 &nbsp".$mon_name[$firstday[mon]-1]."月&nbsp月历";
echo "</FONT>";                             
echo "</TH>";                              
    //表头                               
$weekDay[0] = "日";                           
$weekDay[1] = "";                           
$weekDay[2] = " 2";                           
$weekDay[3] = " 3";                           
$weekDay[4] = " 4";                           
$weekDay[5] = " 5";                           
$weekDay[6] = " 6";                           
echo "<TR ALIGN="center" VALIGN="center">";             
//显示表格行                           
for ($dayNum = 0; $dayNum < 7; $dayNum) {               
  showline($weekDay[$dayNum],"red");                  
}                                    
echo"</TR>";                              
  $toweek=$firstday[wday];//本月天是星期几             
  $lastday=$mon_num[$firstday[mon]-1];//本月最后天是星期几      
  $day_count = 1;//当前应该显示天数                   
$up_to_firstday = 1;//是否显示到本月天              
for ($row = 0; $row <= ($lastday+$toweek-1)/7; $row)//本月有几个星期 
{echo "<TR ALIGN=center VALIGN=center>";             
 for ($col=1; $col<=7; $col)                  
 {                                
     //在第天前面显示都是"空"              
  (($up_to_firstday <= $toweek) ||($day_count>$lastday))
 {                            
  echo "<TD>&nbsp</TD>";             
  $up_to_firstday;               
 }                            
                           
     {                            
        //显示本月中天                    
        showline($day_count,"blue");                
  $day_count;                  
         }                            
 }                                
 echo "</TR>";                          
}                                    
echo "</TABLE>";                            
echo "</CENTER>";                            
?>                                     
</body>                                  
</html>                                   


  http://blog.csdn.net/happy2008/archive/2006/12/03/1427990.aspx



0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: