Calendars made using PHP

Source: Internet
Author: User
Tags php class

This article mainly introduces the use of PHP calendar, the following have effect map, we refer to the use of the bar

  calendar.class.php   Code is as follows:  <?php class Calendar {  private $year;//Current year   private $month;//Current Month   Private $start _weekday; The first day of the month corresponds to the week   private $days; How many days are there in the current month     function __construct () {    $this->year=isset ($_get["year")? $_get["Year"]: Date ("Y");     $this->month=isset ($_get["month"])? $_get["Month"]: Date ("M");       $this->start_weekday=date ("W", Mktime (0, 0, 0, $this->month, 1, $this->year));     $this->days=date ("T", mktime (0, 0, 0, $this->month, 1, $this->year));  }     function out () {   echo ' <table align= ' center ' > ';     $this->chagedate ("test.php");     $this->weekslist ();     $this->dayslist ();    echo ' </table> ';  }     Private function weekslist () {    $week =array (' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ');      echo ' <tr> ';   &NBSPFor ($i =0 $i <count ($week), $i + +)     echo ' <th class= ' fontb ' > '. $week [$i]. ' </th> ';      echo ' </tr> ';  }     Private function dayslist () {   echo ' <tr> ';    //output space (to be vacated before the first day of January) &NB Sp  for ($j =0 $j < $this->start_weekday; $j + +)     echo ' <td> </td> ';        for ($k =1 $k <= $this->days; $k + +) {    $j + +     if ($k ==date (' d ')) &NB Sp    echo ' <td class= ' fontb ' > '. $k. ' </td> ';     Else      echo ' <td> '. $k. ' </td> ';       if ($j%7==0)      echo ' </tr><tr> ';     &NBSP}      //after several spaces    while ($j%7!==0) {    echo ' <td> </td&gt ;';     $J + +;   &nbsp      echo ' </tr> ';  }     Private function prevyear ($year, $month) {    $year= $year-1;      if ($year < 1970)     $year = 1970;      return "year={$year}&month={$month}";   }       Private Function Prevmo Nth ($year, $month) {   if ($month = = 1) {    $year = $year-1;       if ($year < 1970 )       $year = 1970;       $month = 12;    }else{    $month--   }      return "year={$year}&month={$month}";    }       Private Function nextyear ($year, $month) {    $year = $year + 1;   &nbs P  if ($year > 2038)     $year = 2038;      return "year={$year}&month={$month}";   }       Private Function Nextmo Nth ($year, $month) {   if ($month ==12) {    $year + +       ($year > 2100)   &N Bsp   $year = 2100;       $month = 1;    } else{    $month + +              return "year={$year}&month={$month}"; nbsp  }     Private function chagedate ($url = "") {   echo ' <tr> ';    echo ' <td>& Lt;a href= "? '". $this->prevyear ($this->year, $this->month). " > '. ' << '. ' </a></td> ';    echo ' <td><a href= '? $this->prevmonth ($this->year, $this->month). " > '. ' < '. ' </a></td> ';    echo ' <td colspan= ' 3 ' > ';    echo ' <form> ';    echo ' <select name= ' year ' onchange= ' window.location= '. $url. Year= ' +this.options[selectedindex].value+ ' &month= '. $this->month. ' " > ';    for ($sy =1970 $sy <= 2100 $sy + +) {    $selected = ($sy = = $this->year)? "Selected": "";     echo ' <option '. $selected. ' value= '. $sy. ' " > '. $sy. ' </option> ';   &nbsp    echo ' </select> ';    echo ' <select name= ' month '  onchange= ' window.location= '. $url. ' Year= '. $this->year. ' &month= ' +this.options[selectedindex].value ' > ';    for ($sm =1 $sm <=12; $sm + +) {    $selected 1 = ($sm = = $this->month)? "Selected": "";     echo ' <option '. $selected 1. ' value= '. $sm. ' > ' $sm. ' </option> ';   &nbsp    echo ' </select> ';    echo ' </form> ';     echo ' </td> ';        echo ' <td><a href= '? $this->nextyear ($this->year, $this->month). " > '. ' >> '. ' </a></td> ';    echo ' <td><a href= '? $this->nextmonth ($this->year, $this->month). " > '. ' > '. ' </a></td> ';    echo ' </tr> ';  }   &NBSP}?>        test.php      code as follows:  <style>  table {  border:1px solid #050; &nbsp}    .FONTB {  Color:white;   Background:blue; &NBSP}      th {  width:30px;  }    td,th {  height:30px;   Text-align:cen ter   &NBSP}  form {  margin:0px   padding:0px  } </style> <?php  include "Calendar . class.php ";     $calendar =new calendar;     $calendar->out ()?>  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.