Simple Calendar code for PHP implementation

Source: Internet
Author: User
Tags first row

calendar.php
?
/*******************************
* A function to determine whether a leap year
* Can be improved according to more complex algorithms *
*******************************/
function Leap_year ($year)
{
if ($year% 4 = 0)//Basic rule
{
return true; is leap year
}
Else
{
return false;
}
}
/*******************************
* Assign operations to some variables *
* Pay special attention to the February assignment *
*******************************/
function Setup ()
{
Global $mon _num;
$mon _num=array (31,30,31,30,31,30,31,31,30,31,30,31);
Global $mon _name;
$mon _name=array ("One", "two", "three", "four",
"Five", "six", "seven", "eight",
"Nine", "Ten", "11", "12");
if (Leap_year ($firstday [year]))//Basic rule
{
$mon _num[1]=29; is leap year
}
Else
{
$mon _num[1]=28;
}
}
/*******************************
* Display a grid in the table *
* Display the content and color variable *
*******************************/
function ShowLine ($content, $show _color)
{
$begin _mark = "<td width=60 height=25>";
$begin _mark = $begin _mark. " <font color= $show _color> ";
$end _mark = "</FONT></TD>";
Echo $begin _mark. $content. $end _mark;
}
?>
The formal commencement of the <!--calendar program-->
<title>
Community Calendar
</title>
<meta http-equiv=content-type content= "text/html; charset=gb2312 ">
<body>
?
Get the current date
$firstday = getdate (Mktime (0,0,0,date ("M"), 1,date ("Y")));
Setup ();
Show the name of the table
echo "<CENTER>";
echo "<table border=2 cellspacing=4>";
echo "<th colspan=7 height=50>";
echo "<font color=red size=3 >";
echo "$firstday [year] years &nbsp". $mon _name[$firstday [mon]-1]. " Monthly &AMP;NBSP Calendar ";
echo "</FONT>";
echo "</TH>";
Table header
$weekDay [0] = "Day";
$weekDay [1] = "one";
$weekDay [2] = "two";
$weekDay [3] = "three";
$weekDay [4] = "four";
$weekDay [5] = "Five";
$weekDay [6] = "Six";
echo "<tr align=" center "valign=" Center ">";
Show first row of table
for ($dayNum = 0; $dayNum < 7; + + $dayNum) {
ShowLine ($weekDay [$dayNum], "red");
}
echo "</TR>";
$toweek = $firstday [wday];//The first day of the month is the week
$lastday = $mon _num[$firstday [mon]-1];//The last day of the month is the week
$day _count = 1;//The number of days that should currently be displayed
$up _to_firstday = 1;//Whether to show the first day of the month
for ($row = 0; $row <= ($lastday + $toweek-1)/7; + + $row)//A few weeks this month
{echo "<tr align=center valign=center>";
for ($col =1; $col <=7; + + $col)
{
The first day of the show was "empty."
if ($up _to_firstday <= $toweek) | | ($day _count> $lastday))
{
echo "<TD>&nbsp</TD>";
$up _to_firstday++;
}
Else
{
Show one day of the month
ShowLine ($day _count, "Blue");
$day _count++;
}
}
echo "</TR>";
}
echo "</TABLE>";
echo "</CENTER>";
?>
</body>

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.