Home > php教程 > php手册 > PHP日历代码通用函数

PHP日历代码通用函数

WBOY
Release: 2016-06-21 08:57:26
Original
1101 people have browsed it
<?php <br/>//calendar.php<br>//Check if the month and year values exist<br>if ((!$_GET['month']) && (!$_GET['year'])) {<br>   $month = date ("n");<br>   $year = date ("Y");<br>} else {<br>   $month = $_GET['month'];<br>   $year = $_GET['year'];<br>}<br>//Calculate the viewed month<br>$timestamp = mktime (0, 0, 0, $month, 1, $year);<br>$monthname = date("F", $timestamp);<br>//Now let's create the table with the proper month<br>?><br><table style="width: 105px; border-collapse: collapse;" border="1" cellpadding="3" cellspacing="0" bordercolor="#000000"> <br>   <tr> <br>   <td colspan="7" class="calendartodayoff"> <br>    <span style="font-weight: bold;"><?php echo &#36;monthname . " " . &#36;year; ?></span><br>   </td> <br>   </tr> <br>   <tr> <br>   <td class="calendartodayoff"> <br>    <span style="font-weight: bold;">Su</span><br>   </td> <br>   <td class="calendartodayoff"> <br>    <span style="font-weight: bold;">M</span><br>   </td> <br>   <td class="calendartodayoff"> <br>    <span style="font-weight: bold;">Tu</span><br>   </td> <br>   <td class="calendartodayoff"> <br>    <span style="font-weight: bold;">W</span><br>   </td> <br>   <td class="calendartodayoff"> <br>    <span style="font-weight: bold;">Th</span><br>   </td> <br>   <td class="calendartodayoff"> <br>    <span style="font-weight: bold;">F</span><br>   </td> <br>   <td class="calendartodayoff"> <br>    <span style="font-weight: bold;">Sa</span><br>   </td> <br>   </tr> <br>   <?php <br/>    $monthstart = date("w", $timestamp);<br>    $lastday = date("d", mktime (0, 0, 0, $month + 1, 0, $year));<br>    $startdate = -$monthstart;<br>   <br>    //Figure out how many rows we need.<br>    $numrows = ceil (((date("t",mktime (0, 0, 0, $month + 1, 0, $year)) + $monthstart) / 7));<br>   <br>    //Let's make an appropriate number of rows...<br>    for ($k = 1; $k      ?><tr> <?php <br/>     //Use 7 columns (for 7 days)...<br>     for ($i = 0; $i       $startdate++;<br>      if (($startdate $lastday)){<br>       //If we have a blank day in the calendar.<br>       ?><td style="background: #FFFFFF;"> </td> <?php <br/>      } else {<br>                <br>       if ($startdate == date("j") && $month == date("n") && $year == date("Y")){<br>        ?><td class="calendartodayoff" .>',event);" ><?php echo date ("j"); ?> </td> <?php <br/>       } else {<br>        ?><td class="calendaroff" .>',event);" ><?php echo &#36;startdate; ?> </td> <?php <br/>       }<br>      }<br>     }<br>     ?></tr> <?php <br/>    }<br>   ?>    <br> </table>



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template