Is the effect, just learn php, write a perpetual calendar to play ~
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>php Calendar </title>
<style>
#dusk {
Text-align:center;
padding-top:50px;
}
h1{
Text-align:center;
}
#check
{
width:500px;
margin:0 Auto;
Text-align:center;
}
</style>
<body>
<?php
Header ("Content-type:text/html;charset=utf-8");
function Inputcheck ()
{
if (@preg_match ('/\d{1,4}/', $_get[' y ') ==1)//The Regular expression input box is judged, it must be 1-4 digits, otherwise it will return false
{
return TRUE;
}
Else
{
echo "<center>";
echo "<font id=inputerror color= ' red ' size=20px text-align=center> Please enter the correct year!</font>";
echo "</center>";
return FALSE;
}
}
if (!inputcheck ())
{
$year = Date (' Y ');//Get Current year
$month = Date (' m ');//Gets the current month
$days = date (' t ', Strtotime ("$year-$month-1"));//Get the number of days in the current month
$week = Date (' W ', Strtotime ("$year-$month-1"));//Get Current Week
echo "<center>";
echo "echo "</center>";
}
Else
{
@ $year = $_get[' y ']? $_get[' y ': date (' Y '), or//If a parameter passed by the Get method is used to get the year using the Get method, if it is not in the current year
@ $month = $_get[' m ']? $_get[' m ': Date (' m ');
$days = date (' t ', Strtotime ("$year-$month-1"));
$week = Date (' W ', Strtotime ("$year-$month-1"));
echo "<center>";
echo "echo "</center>";
}
echo "<center>";
echo "<table width=700px border=2px>";//Drawing table
echo "<tr>";
echo "<th> Sunday </th>";
echo "<th> Monday </th>";
echo "<th> Tuesday </th>";
echo "<th> Wednesday </th>";
echo "<th> Thursday </th>";
echo "<th> Friday </th>";
echo "<th> Saturday </th>";
echo "</tr>";
for ($i = 1-$week; $i < $days;)
{
echo "<tr>";
for ($j = 0; $j < 7; $j + +)
{
if ($i < 1 | | $i > $days)
{
if ($j% 2 = = 0)//change the color of the line
{
echo "<td bgcolor= #ccc > </td>";
}
Else
{
echo "<td> </td>";
}
}
Else
{
if ($j%2 = = 0)
{
if ($year ==date (' Y ') && $month ==date (' m ') && $i ==date (' d '))//The current date is marked in blue
{
echo "<td bgcolor=blue>{$i}</td>";
}
Else
{
echo "<td bgcolor= #A9A9A9 >{$i}</td>";
}
}
Else
{if ($year ==date (' Y ') && $month ==date (' m ') && $i ==date (' d '))
{
echo "<td bgcolor=blue>{$i}</td>";
}
Else
{
echo "<td>{$i}</td>";
}
}
}
$i + +;
}
echo "</tr>";
}
echo "</table>";
if ($month ==1)//Judge last month and next month
{
$preyear = $year-1;
$premonth = 12;
}
else{
$preyear = $year;
$premonth = $month-1;
}
if ($month = = 12)
{
$nextyear = $year + 1;
$nextmonth = 1;
}
Else
{
$nextyear = $year;
$nextmonth = $month + 1;
}
$last _year = $year-1;
$next _year = $year + 1;
$nowyear = Date (' Y ');
$nowmonth = Date (' m ');
echo "</center>";//The A tag below
echo "<div id=dusk>
<a href= ' index.php?y={$last _year}&m={$month} ' > Last year </a>
<a href= ' index.php?y={$preyear}&m={$premonth} ' > Last month </a>
|
<a href= ' index.php?y={$nextyear}&m={$nextmonth} ' > next month </a>
<a href= ' index.php?y={$next _year}&m={$month} ' > next year </a>
<br>
<a href= ' index.php?y={$nowyear}&m={$nowmonth} ' > Back to Current month </a>
</div> ";///month drop-down menu
echo "<div id=check><form action=" method= ' Get ' >
<input type= ' text ' name= ' y ' size= ' 5 ' > year
<select id= ' name= ' m ' >
<option value= ' 1 ' >1</option>
<option value= ' 2 ' >2</option>
<option value= ' 3 ' >3</option>
<option value= ' 4 ' >4</option>
<option value= ' 5 ' >5</option>
<option value= ' 6 ' >6</option>
<option value= ' 7 ' >7</option>
<option value= ' 8 ' >8</option>
<option value= ' 9 ' >9</option>
<option value= ' >10</option>
<option value= ' one ' >11</option>
<option value= ' >12</option>
</select>
<input type= ' Submit ' name= ' Sub ' value= ' Enquiry ' >
</form>
</div> ";
?>
</body>
PHP Perpetual calendar