国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

PHP實現(xiàn)簡單日歷類編寫

瀏覽:10日期:2022-09-09 10:27:36

用PHP實現(xiàn)日歷類的編寫,供大家參考,具體內(nèi)容如下

calendar.class.php

<?php/** 創(chuàng)建一個日歷類***/ //修改默認時區(qū) date_default_timezone_set('PRC'); class Calendar { private $year; private $month; private $day; //當月總天數(shù) private $first_week; //每月的第一天是星期幾 //構(gòu)造函數(shù) function __construct() { $this->year = isset($_GET[’year’])?$_GET[’year’]:date('Y'); $this->month = isset($_GET['month'])?$_GET['month']:date('m'); $this->first_week = date('w', mktime(0, 0 ,0, $this->month, 1, $this->year)); $this->day = date('t', mktime(0, 0 ,0, $this->month, 1, $this->year)); } function showCalendar() { // echo $this->year.'年'.$this->month.'月'.$this->first_week.'天'.$this->day; echo '<table align=’center’>'; //用表格輸出 $this->chageDate('index.php'); //用于用戶調(diào)整年月份 $this->weekList();//顯示星期 $this->dayList(); //顯示天數(shù) echo '</table>'; } //1、顯示星期 private function weekList() { $week = array('日','一','二','三','四','五','六'); echo '<tr>'; for ($i = 0; $i < count($week); $i++) { echo '<th>'.$week[$i].'</th>'; } echo '</tr>'; } //2.顯示天數(shù) private function dayList() { $color = '#2ca50c'; echo '<tr>'; for ($i = 0; $i < $this->first_week; $i++) { //輸出空格,彌補當前月空缺部分 echo '<td bgcolor=’#2ca50c’> </td>'; } for ($k = 1; $i <= $this->day; $k++) { $i++; if ($k == date('d')) echo '<td id=’nowd’>'.$k.'</td>'; //是今天,加效果 else echo '<td bgcolor=$color>'.$k.'</td>'; if ($i % 7 == 0) { echo '</tr><tr>'; //每7天一次換行 if ($i % 2 == 0) $color = '#2ca50c'; else $color = '#9ddb27'; //實現(xiàn)各行換色的效果 } } while ($i % 7 != 0) { //將剩余的空格補完 echo '<td bgcolor=’#2ca50c’> </td>'; $i++; } echo '</tr>'; } //3、用于用戶調(diào)整天數(shù) private function chageDate($url='index.php') { echo '<tr>'; echo '<caption><h1>'.$this->year.'年'.$this->month.'月</h1></caption>'; echo '</tr>'; echo '<tr>'; echo '<td>'.'<a href=’?'.$this->prevYear($this->year,$this->month).'’>'.'<'.'</a>'; echo '<td>'.'<a href=’?'.$this->prevMonth($this->year,$this->month).'’>'.'<<'.'</a>'; echo '<td colspan=’3’>'; echo ’<select οnchange='window.location=’’.$url.’?year=’+this.options[selectedIndex].value+’&month=’.$this->month.’’'>’; for ($year = 2038; $year >= 1970; $year--) { $selected = ($year == $this->year)?'selected':''; echo ’<option ’.$selected. ’ value='’.$year.’'>’.$year.’</option>’; //echo ’<option ’.$selected.’ value='’.$year.’'>’.$year.’</option>’; } echo '</select>'; echo ’<select name='month' οnchange='window.location=’’.$url.’?year=’.$this->year.’&month=’+this.options[selectedIndex].value'>’; for($month=1;$month <= 12;$month++){ $selected1 = ($month == $this->month) ? 'selected' : ''; echo ’<option ’.$selected1.’ value='’.$month.’'>’.$month.’</option>’; } echo ’</select>’; echo '</td>'; echo '<td>'.'<a href=’?'.$this->nextMonth($this->year,$this->month).'’>'.'>>'.'</a>'; echo '<td>'.'<a href=’?'.$this->nextYear($this->year,$this->month).'’>'.'>'.'</a>'; echo '</tr>'; } private function prevYear($year, $month) { //獲取上一年的數(shù)據(jù) $year--; if ($year < 1970) $year = 1970; return 'year={$year}&month={$month}'; } private function prevMonth($year, $month) { if ($month == 1) { $year--; if ($year < 1970) $year = 1970; $month = 12; }else $month--; return 'year={$year}&month={$month}'; } private function nextYear($year, $month) { //獲取上一年的數(shù)據(jù) $year++; if ($year > 2038) $year = 2038; return 'year={$year}&month={$month}'; } private function nextMonth($year, $month) { if ($month == 12) { $year++; if ($year > 2038) $year = 2038; $month = 1; }else $month++; return 'year={$year}&month={$month}'; } }

主頁 index.php

<!doctype html><html><head><meta charset='utf-8'><title>日歷顯示</title><style> table { border:1px solid #050; margin: 100px auto; } th { width: 30px; background-color: #0CC; color: #fff; height: 30px; font-size: 20px; } #nowd { color: yellow; background: #F00; } td { width: 30px; text-align: center; height: 25px; color: #fff; } a { display: block; width: 35px; height: 35px; background: #0F9; text-decoration: none; text-align: center; line-height: 35px; } a:hover { background: #CF0; color: #fff; font-size: 20px; }</style></head> <body> <?php include 'calendar.class.php'; $ca = new Calendar(); $ca->showCalendar(); ?></body></html>

PHP實現(xiàn)簡單日歷類編寫

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: PHP
相關(guān)文章:
主站蜘蛛池模板: 福利姬在线精品观看 | 亚洲国产激情 | 狠狠色综合色综合网站久久 | 91精品视频播放 | 韩国三级大全久久网站 | 国产日韩一区二区三区 | 成人男女网18免费看 | 男女免费视频网站 | 一区二区精品在线 | 在线观看毛片网站 | aaaaaaa毛片 | 日本欧美一区二区三区在线 | 免费精品久久久久久中文字幕 | 日本三级香港三级网站 | 欧美日本视频一区 | 免费国产高清精品一区在线 | 免费看成人播放毛片 | 亚洲一区在线播放 | 国产精品一区二区三区四区五区 | 久久99久久精品免费思思6 | 日韩一级精品久久久久 | 久久黄色免费网站 | 97在线免费看视频 | 久久99精品久久久久久综合 | 精品国产免费观看 | 国产成人精品日本亚洲专区6 | 欧美一级高清片欧美国产欧美 | 一级做a爰片久久毛片 | 51久久夜色精品国产 | avwww在线| 69视频成人 | 亚洲视频一区二区三区 | 亚洲深夜福利视频 | 深夜福利视频大全在线观看 | 一级毛片黄片 | 欧美成人激情在线 | 国产精品视频一区二区三区 | 亚洲综合伊人色一区 | 亚洲永久 | 俄罗斯极品美女毛片免费播放 | 欧美日韩视频二区三区 |