php日历类

  •        没有写之前觉的,写一个日历很神奇,写完之后发现也不过如此,仅仅是几个php函数的组合。不要担心自己不会,只要用心的去想,你就一定可以搞定。就像我计算机的启蒙老师说的,不会的问题一定要认真的去做,认真的去解决,做完了你才突然的发现,因为一给小问题,你学到了很多的东西。
  • php日历类
  • <?php

        class calendar
        {
           public $mounth; //current mounth
           public $year;   // current year

           function __construct()
           {
               $this->year = $this->get_year();
               $this->mounth = $this->get_mounth();
           }

           function get_mounth()
           {
               $mounth = date("n",time());
               return $mounth;
           }

           function get_year()
           {
               $year = date("Y",time());
               return $year;
           }

           function get_day()
           {
               $day = date("j",time());
               return $day;
           }

           function get_year_mounth_one_number_week()
           {
               $mounth_one_day = idate("w",mktime(0,0,0,$this->mounth,1,$this->year));
               return $mounth_one_day;
           }

           function get_mounth_total_days()
           {
               $total_days = idate("t",mktime(0,0,0,$this->mounth,1,$this->year));
               return $total_days;
           }

           function mounth_num_is_week($day)
           {
               $week = idate("w",mktime(0,0,0,$this->mounth,$day,$this->year));
               return $week;
           }

           function display()
           {
               $array = array("日","一","二","三","四","五","六");
               echo "<table border = '0'><tr>";
               foreach($array as $day)
               {
                    echo "<td>".$day."</td>";
               }
               echo "</tr><tr>";
               $i=0;
               while($i< $this->get_year_mounth_one_number_week())
               {
                    echo "<td>&nbsp;</td>";
                    $i++;
               }
               $j=1;
               while($j<=$this->get_mounth_total_days())
               {
                    if($j == $this->get_day())
                    {
                        echo  "<td bgcolor='red'>".$j."</td>";
                    }
                    else
                    {
                        echo "<td>".$j."</td>";
                    }

                    if($this->mounth_num_is_week($j) == 6)
                    {
                        echo "</tr><tr>";
                    }
                    $j++;
               }
               echo "</tr></table>";
           }
        }

    ?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值