PHP Calendar Production Code sharing _php Tutorial

Source: Internet
Author: User


calendar.class.php

Copy the Code code as follows:
Class Calendar {
Private $year; The current year
Private $month; The current month
Private $start _weekday; The first day of the month corresponds to the week
Private $days; The current month altogether how many days

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 '





'; $this->chagedate ("test.php"); $this->weekslist (); $this->dayslist (); Echo '
';
}

Private Function Weekslist () {
$week =array (' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' VI ');

Echo ';
for ($i =0; $i
Echo '. $week [$i]. ";

Echo ';
}

Private Function Dayslist () {
Echo ';
Output space (the first day of the current January will be empty)
for ($j =0; $j < $this->start_weekday; $j + +)
Echo ';


for ($k =1; $k <= $this->days; $k +) {
$j + +;
if ($k ==date (' d '))
Echo '. $k. ';
Else
Echo '. $k. ';

if ($j%7==0)
Echo ';

}

Several spaces behind
while ($j%7!==0) {
Echo ';
$j + +;
}

Echo ';
}

Private Function Prevyear ($year, $month) {
$year = $year-1;

if ($year < 1970)
$year = 1970;

Return "year={$year}&month={$month}";
}


Private Function Prevmonth ($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;

if ($year > 2038)
$year = 2038;

Return "year={$year}&month={$month}";
}


Private Function Nextmonth ($year, $month) {
if ($month ==12) {
$year + +;

if ($year > 2100)
$year = 2100;

$month = 1;
}else{
$month + +;
}

Return "year={$year}&month={$month}";
}

Private Function chagedate ($url = "") {
Echo ';
Echo ' Prevyear ($this->year, $this->month). ' " > '. ' << '. ';
Echo ' Prevmonth ($this->year, $this->month). ' " > '. ' < '. ';
Echo ';
Echo ';
Echo ';


Echo ' Nextyear ($this->year, $this->month). ' " > '. ' >> '. ';
Echo ' Nextmonth ($this->year, $this->month). ' " > '. ' > '. ';
Echo ';
}

}
?>

test.php

Copy the Code code as follows:

Include "calendar.class.php";

$calendar =new Calendar;

$calendar->out ();
?>

http://www.bkjia.com/PHPjc/718612.html www.bkjia.com true http://www.bkjia.com/PHPjc/718612.html techarticle calendar.class.php Copy the code as follows: PHP class Calendar {private $year;//Current year private $month;//Current Month private $start _weekda Y The first day of the month corresponds to ...

  • 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.

    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.