91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用PHP編寫一個日歷功能

發布時間:2020-11-06 16:27:34 來源:億速云 閱讀:279 作者:Leah 欄目:開發技術

本篇文章為大家展示了使用PHP編寫一個日歷功能,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

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

calendar.class.php

<&#63;php
/*
* 創建一個日歷類
*
*
*/
 //修改默認時區
 date_default_timezone_set("PRC");
 
 class Calendar {
  private $year;
 private $month;
 private $day; //當月總天數
 private $first_week; //每月的第一天是星期幾
 
 //構造函數
 function __construct() {
  $this->year = isset($_GET['year'])&#63;$_GET['year']:date("Y");
  $this->month = isset($_GET["month"])&#63;$_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><h2>".$this->year."年".$this->month."月</h2></caption>"; 
  echo "</tr>";
  echo "<tr>";
  echo "<td>"."<a href='&#63;".$this->prevYear($this->year,$this->month)."'>"."<"."</a>";
  echo "<td>"."<a href='&#63;".$this->prevMonth($this->year,$this->month)."'>"."<<"."</a>";
  
  echo "<td colspan='3'>";
   echo '<select οnchange="window.location=\''.$url.'&#63;year=\'+this.options[selectedIndex].value+\'&month='.$this->month.'\'">';
    for ($year = 2038; $year >= 1970; $year--) {
    $selected = ($year == $this->year)&#63;"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.'&#63;year='.$this->year.'&month=\'+this.options[selectedIndex].value">';
  for($month=1;$month <= 12;$month++){
   $selected1 = ($month == $this->month) &#63; "selected" : "";
   echo '<option '.$selected1.' value="'.$month.'">'.$month.'</option>';
  }
  echo '</select>';
  echo "</td>";
  
  
  echo "<td>"."<a href='&#63;".$this->nextMonth($this->year,$this->month)."'>".">>"."</a>";
  echo "<td>"."<a href='&#63;".$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>
 <&#63;php
 include "calendar.class.php";
 $ca = new Calendar();
 $ca->showCalendar();
 &#63;>
</body>
</html>

使用PHP編寫一個日歷功能

上述內容就是使用PHP編寫一個日歷功能,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

定兴县| 栾川县| 大庆市| 蒲城县| 中西区| 搜索| 安陆市| 分宜县| 明光市| 黄骅市| 错那县| 诏安县| 新巴尔虎左旗| 谢通门县| 万载县| 北碚区| 巍山| 沛县| 丹阳市| 华宁县| 温泉县| 五河县| 菏泽市| 韶山市| 内乡县| 雷波县| 五台县| 突泉县| 奉贤区| 满洲里市| 岱山县| 怀宁县| 宁河县| 安国市| 汉阴县| 米易县| 诸暨市| 皮山县| 醴陵市| 昭苏县| 崇阳县|