"PHP" Production calendar

Source: Internet
Author: User

This issue tells us two ways to make a calendar out of PHP, and because of the convenience of the PHP date function, it makes the process of making a calendar quite simple.

Problem Description:

1, take the current date, and coloring display;
2, according to the current date, judging how many days this month, a number is the week;
3. Complete this month's calendar display

Method One, automatically take the current date, the code is as follows

Date_default_timezone_set ("PRC"); $time=getdate(); $mday=$time["Mday"]; $mon=$time["Mon"]; $year=$time["Year"]; if($mon==4| |$mon==6| |$mon==9| |$mon==11){        $day= 30; }ElseIf($mon==2){        if(($year%4==0&&$year%100!=0) | |$year%400==0){            $day= 29; }Else{            $day= 28; }    }Else{        $day= 31; }        $w=getdate(Mktime(0,0,0,$mon, 1,$year)) ["Wday"]; $date=function($day,$w){        Echo"<table border= ' 1 ' >"; Echo"<tr><th> Sunday </th><th> Monday </th><th> Tuesday </th><th> Wednesday </th> <th> Thursday </th><th> Friday </th><th> Saturday </th></tr> "; $arr=Array();  for($i= 1;$i<=$day;$i++){            Array_push($arr,$i); }        if($w>=1&&$w<=6){             for($m= 1;$m<=$w;$m++){                Array_unshift($arr,""); }        }        $n=0;  for($j= 1;$j<=Count($arr);$j++){            $n++; if($n==1)Echo"<tr>"; Global $mday; if($mday==$arr[$j-1]){                Echo"<td width= ' 80px ' style= ' background-color:greenyellow; ' > ".$arr[$j-1]. " </td> "; }Else{                Echo"<td width= ' 80px ' >".$arr[$j-1]. " </td> "; }                        if($n==7){                Echo"</tr>"; $n=0; }        }        if($n!=7)Echo"</tr>"; Echo"</table>";    }; $date($day,$w);

The operation results are as follows

Method Two, specify the current date, the code is as follows

//Here is the time input Echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The current time stamp is: "; Echo $today=Mktime(9,34,56,06,02,2017); Echo"</br>"; Echo"</br>"; $r=Date("L",$today);//Yun Common year $w=Date("N",$today);//Week $m=Date("N",$today);//Month $d=Date("J",$today);if($m==1| |$m==3| |$m==5| |$m==7| |$m==8| |$m==10| |$m==12){    $days=31;}ElseIf($m==4| |$m==6| |$m==9| |$m==11){    $days=30;}ElseIf($m==2){    if($r==1){        $days=29; }Else{        $days=28; }}Else{    Echo"Wrong date!!!" ";} $day=1;$week=0;$count=($days+$w)/7; Echo"<table border= ' 1 ' width= ' >"; Echo<<<th<tr style= "Background-color: #ccc;" > <th style= "color:red;" > Sunday </th> <th> Monday </th> <th> Tuesday </th> <th> Wednesday </th > <th> Thursday </th> <th> Friday </th> <th style= "Color:green;" > Saturday </th> </tr>th;  for($i= 0;$i<=$count;$i++){        Echo"<tr>";  for($j= 0;$j<7;$j++){            if(($week<$w)|| ($day>$days)){                Echo"<td></td>"; $week++; }Else{                if($day==$d){                Echo"<td bgcolor= ' green '; >{$day}</td> "; $day++; }Else{                Echo"<td>{$day}</td> "; $day++; }            }                    }        if($day>$days){             Break; }        Echo"</tr>"; }    Echo"</table>";Echo"</br>";Echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Current time is:";Echo Date("Y-m-d h:i:s week n A",$today);

Running results such as

The effect is perfect, and then the first two on the basis of a slight improvement on the calendar can be obtained, PHP function is so powerful

Code implementation Thanks @ Xavier @q's front-end world two great gods

Do not forward without permission!!!

"PHP" Production calendar

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.