PHP實現的簡單日曆類_PHP

來源:互聯網
上載者:User
關鍵字 PHP 簡單 日曆
本文執行個體講述了PHP實現的簡單日曆類。分享給大家供大家參考。

具體實現代碼如下:

代碼如下:

date_default_timezone_set("etc/gmt-8");
header("Content-type: text/html; charset=utf-8");
class calendar{
var $t = array();
var $datesofmonth = array('1'=>'31','2'=>'28','3'=>'31','4'=>'30','5'=>'31','6'=>'30','7'=>'31','8'=>'31','9'=>'30','10'=>'31','11'=>'30','12'=>'31');
var $y,$m,$d;
function set($time){
$this->t = getdate($time);
$this->y = $this->t['year'];
$this->m = $this->t['mon'];
$this->d = date('d',$time);
}
function isrun(){
return ($this->y%400==0 || ($this->y%4==0 && $this->y%100==0)) ? 1 : 0;
}
function first(){
$time = mktime(0,0,0,$this->m,1,$this->y);
$time = getdate($time);
return $time['wday'];
}
function html(){
$isrun = $this->isrun();
$this->datesofmonth[2] = $isrun==1 ? 29: 28;
$html .= "
























n"; $html .= " n"; $html .= " bitsCN.com n"; $html .= " n"; $first = $this->first(); for($i=0; $i<$first; $i++){ $html .= " "; } $count = $this->datesofmonth[$this->m]+$first; for ($i=1; $i<= $this->datesofmonth[$this->m]; $i++){ $style = $i==$this->d ? ' style="color:red;font-weight:bold;"' : '' ; $html .= " "; if (($i==7%$first || ($i+$first)%7==0) && $i<$count){ $html .= " n "; } } $count = 7-$count%7; if ($count<7){ for ($i=0; $i<$count; $i++){ $html .= " "; } } $html .= " n"; $html .= "
上一月 {$this->y}年 {$this->m}月 下一月
星期天 星期一 星期二星期三 星期四 星期五 星期六
$i
n";
return $html;
}
}
$calendar = new calendar();
$calendar->set(time());
echo $calendar->html();

希望本文所述對大家的php程式設計有所協助。

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.