PHP Calendar Code Common functions

Source: Internet
Author: User
<?php
calendar.php
Check if the month and year values exist
if ((!$_get[' month ']) && (!$_get[' year ')) {
$month = Date ("n");
$year = Date ("Y");
} else {
$month = $_get[' month '];
$year = $_get[' year '];
}
Calculate the viewed Month
$timestamp = mktime (0, 0, 0, $month, 1, $year);
$monthname = Date ("F", $timestamp);
Now let's create the table with the proper month
?>
<table style= "WIDTH:105PX; Border-collapse:collapse "border=" 1 "cellpadding=" 3 "cellspacing=" 0 "bordercolor=" #000000 ">
<tr>
&LT;TD colspan= "7" class= "Calendartodayoff" >
<span style= "Font-weight:bold;" ><?php Echo $monthname. " " . $year;?></span>.
</td>
</tr>
<tr>
&LT;TD class= "Calendartodayoff" >
<span style= "Font-weight:bold;" >Su</span>
</td>
&LT;TD class= "Calendartodayoff" >
<span style= "Font-weight:bold;" >M</span>
</td>
&LT;TD class= "Calendartodayoff" >
<span style= "Font-weight:bold;" >Tu</span>
</td>
&LT;TD class= "Calendartodayoff" >
<span style= "Font-weight:bold;" >W</span>
</td>
&LT;TD class= "Calendartodayoff" >
<span style= "Font-weight:bold;" >Th</span>
</td>
&LT;TD class= "Calendartodayoff" >
<span style= "Font-weight:bold;" >F</span>
</td>
&LT;TD class= "Calendartodayoff" >
<span style= "Font-weight:bold;" >Sa</span>
</td>
</tr>
<?php
$monthstart = Date ("W", $timestamp);
$lastday = Date ("D", mktime (0, 0, 0, $month + 1, 0, $year));
$startdate =-$monthstart;

Figure out how many rows we need.
$numrows = Ceil ((Date ("T", mktime (0, 0, 0, $month + 1, 0, $year)) + $monthstart)/7);

Let ' s make an appropriate number of rows ...
for ($k = 1; $k <= $numrows; $k + +) {
? ><tr><?php
Use 7 columns (for 7 days) ...
for ($i = 0; $i < 7; $i + +) {
$startdate + +;
if (($startdate <= 0) | | ($startdate > $lastday)) {
If We have a blank day in the calendar.
? ><td style= "background: #FFFFFF;" > </td><?php
} else {

if ($startdate = = Date ("J") && $month = = Date ("n") && $year = = Date ("Y")) {
? ><td class= "Calendartodayoff"-". $month. "-" . $startdate?> ', event); "><?php Echo Date (" J ");? ></td><?php
} else {
? ><td class= "Calendaroff"-". $month. "-" . $startdate;?> ', event]; ><?php echo $startdate;? ></td><?php
}
}
}
? ></tr><?php
}
?>
</table>


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.