电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

PHP實現簡單日歷類編寫

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

用PHP實現日歷類的編寫,供大家參考,具體內容如下

calendar.class.php

<?php/** 創建一個日歷類***/ //修改默認時區 date_default_timezone_set('PRC'); class Calendar { private $year; private $month; private $day; //當月總天數 private $first_week; //每月的第一天是星期幾 //構造函數 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'); //用于用戶調整年月份 $this->weekList();//顯示星期 $this->dayList(); //顯示天數 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.顯示天數 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'; //實現各行換色的效果 } } while ($i % 7 != 0) { //將剩余的空格補完 echo '<td bgcolor=’#2ca50c’> </td>'; $i++; } echo '</tr>'; } //3、用于用戶調整天數 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) { //獲取上一年的數據 $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) { //獲取上一年的數據 $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實現簡單日歷類編寫

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

標簽: PHP
相關文章:
主站蜘蛛池模板: 低粘度纤维素|混凝土灌浆料|有机硅憎水粉|聚羧酸减水剂-南京斯泰宝 | 苏商学院官网 - 江苏地区唯一一家企业家自办的前瞻型、实操型商学院 | 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | 不锈钢复合板|钛复合板|金属复合板|南钢集团安徽金元素复合材料有限公司-官网 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 | 诸城网站建设-网络推广-网站优化-阿里巴巴托管-诸城恒泰互联 | 珠光砂保温板-一体化保温板-有釉面发泡陶瓷保温板-杭州一体化建筑材料 | 洗瓶机厂家-酒瓶玻璃瓶冲瓶机-瓶子烘干机-封口旋盖压盖打塞机_青州惠联灌装机械 | 无痕胶_可移胶_无痕双面胶带_可移无痕胶厂家-东莞凯峰 | 冷凝锅炉_燃气锅炉_工业燃气锅炉改造厂家-北京科诺锅炉 | 全温度恒温培养摇床-大容量-立式-远红外二氧化碳培养箱|南荣百科 | 岸电电源-60HZ变频电源-大功率变频电源-济南诚雅电子科技有限公司 | 上海公众号开发-公众号代运营公司-做公众号的公司企业服务商-咏熠软件 | 欧美日韩国产一区二区三区不_久久久久国产精品无码不卡_亚洲欧洲美洲无码精品AV_精品一区美女视频_日韩黄色性爱一级视频_日本五十路人妻斩_国产99视频免费精品是看4_亚洲中文字幕无码一二三四区_国产小萍萍挤奶喷奶水_亚洲另类精品无码在线一区 | 手表腕表维修保养鉴定售后服务中心网点 - 名表维修保养 | 烟气在线监测系统_烟气在线监测仪_扬尘检测仪_空气质量监测站「山东风途物联网」 | 广州市哲铭油墨涂料有限公司,水性漆生产研发基地 | 高柔性拖链电缆_卷筒电缆_耐磨耐折聚氨酯电缆-玖泰特种电缆 | 烟气在线监测系统_烟气在线监测仪_扬尘检测仪_空气质量监测站「山东风途物联网」 | 过跨车_过跨电瓶车_过跨转运车_横移电动平车_厂区转运车_无轨转运车 | 全自动包衣机-无菌分装隔离器-浙江迦南科技股份有限公司 | 本安接线盒-本安电路用接线盒-本安分线盒-矿用电话接线盒-JHH生产厂家-宁波龙亿电子科技有限公司 | BOE画框屏-触摸一体机-触控查询一体机-触摸屏一体机价格-厂家直销-触发电子 | 深圳VI设计-画册设计-LOGO设计-包装设计-品牌策划公司-[智睿画册设计公司] | 股票入门基础知识_股票知识_股票投资大师_格雷厄姆网 | 信阳市建筑勘察设计研究院有限公司| 圈酒招商网【jiushuitv.com】_酒水招商_代理_加盟平台 | 深圳高新投三江工业消防解决方案提供厂家_服务商_园区智慧消防_储能消防解决方案服务商_高新投三江 | 杭州网络公司_百度SEO优化-外贸网络推广_抖音小程序开发-杭州乐软科技有限公司 | 广州昊至泉水上乐园设备有限公司 | 净水器代理,净水器招商,净水器加盟-FineSky德国法兹全屋净水 | 西安烟道厂家_排气道厂家_包立管厂家「陕西西安」推荐西安天宇烟道 | 杭州翻译公司_驾照翻译_专业人工翻译-杭州以琳翻译有限公司官网 组织研磨机-高通量组织研磨仪-实验室多样品组织研磨机-东方天净 | 自进式锚杆-自钻式中空注浆锚杆-洛阳恒诺锚固锚杆生产厂家 | 温控器生产厂家-提供温度开关/热保护器定制与批发-惠州市华恺威电子科技有限公司 | 拖链电缆_柔性电缆_伺服电缆_坦克链电缆-深圳市顺电工业电缆有限公司 | 盘扣式脚手架-附着式升降脚手架-移动脚手架,专ye承包服务商 - 苏州安踏脚手架工程有限公司 | 展厅设计公司,展厅公司,展厅设计,展厅施工,展厅装修,企业展厅,展馆设计公司-深圳广州展厅设计公司 | 压片机_高速_单冲_双层_花篮式_多功能旋转压片机-上海天九压片机厂家 | 深圳市超时尚职业培训学校,培训:月嫂,育婴,养老,家政;化妆,美容,美发,美甲. | 河南道路标志牌_交通路标牌_交通标志牌厂家-郑州路畅交通 |