Php simple calendar implementation program code

Source: Internet
Author: User

The calendar application should be well reflected in the independent blog. Both the wp blog in php and the z_blog blog in ASP have applied the Calendar function, that is, the log is archived. When we want to view the previously released logs, we can view each article clearly by calling out the log archive.

Because I recently wrote a calendar project function, I naturally thought of archiving logs. In fact, it is not very difficult to implement this function. First, I need to have a calendar form to intuitively display the calendar, the time for processing the date is handed over to the programming code, such as PHP. To view the previous documents, that is, to flip the calendar forward, you need to submit the calendar time, then, it is displayed in the form.

Effect

The following is a new PHP Calendar function. Here, a file is used to write the Calendar function. The file is not very large and there is a comment. It is a simple principle function, the accept part is handled by PHP, and the display part uses tables. If you are using a PHP calendar project, you can directly perform secondary development.

The Code is as follows: Copy code

 

<? Php
// Peel off date
Date_default_timezone_set ("Asia/Harbin ");
$ Riqi = getdate ();
$ Nian = $ riqi ['Year'];
$ Yue = $ riqi ['mon'];
$ Ri = $ riqi ['mday'];
$ Hour = $ riqi ['urs'];
$ Min = $ riqi ['minutes '];
$ Miao = $ riqi ['seconds'];
// Form judgment
If (isset ($ _ GET ["yue"]) {
$ Yue = intval ($ _ GET ["yue"]);
}
If (isset ($ _ GET ["nian"]) {
$ Nian = intval ($ _ GET ["nian"]);
}
// Several days a month
$ Tianshu = date ('T', mktime (0, 0, 0, $ yue, 1, $ nian ));
// Day of the week on the first day of the month
$ Yuez = date ('w', mktime (0, 0, 0, $ yue, 1, $ nian ));
$ Tian = 0;
?>
<! -- Print the calendar -->
<Table border = "1" width = "80%">
<Tr>
& Lt; td width = "60%" & gt;
<Table border = "1" width = "100%">
<Tr>
<Th colspan = "7"> calendar <? Php echo $ nian. "year". $ yue. "month"?> & Nbsp; current time: <? Php echo $ hour. ':'. $ min. ':'. $ miao;?> </Th>
<Tr>
<Tbody bgcolor = "# FF9900">
<Tr>
<Td> day </td>
<Td> 1 </td>
<Td> 2 </td>
<Td> 3 </td>
<Td> 4 </td>
<Td> 5 </td>
<Td> 6 </td>
</Tr>
</Tbody>
<Tbody>
<? Php for ($ h = 1; $ h <= 6; $ h ++) {?>
<Tr>
<? Php for ($ l = 1; $ l <= 7; $ l ++) {?>
<Td bgcolor = "<? Php if ($ tian + 1 === ri) {echo "# FF6666" ;}?> "Align =" center ">
<? Php
If ($ h * $ l <= $ yuez & $ h = 1 ){
Echo '& nbsp ;';
} Elseif ($ tian <$ tianshu ){
Echo ++ $ tian;
} Else {
Echo '& nbsp ;';
}
?>
</Td>
<? Php }?>
</Tr>
<? Php }?>
</Tbody>
</Table>
</Td>
<! -- Turning pages -->
<Td>
<A href = "? Nian = <? Php echo $ nian-1;?> & Yue = <? Php echo $ yue;?> "> Last year </a>
<A href = "? Nian = <? Php echo $ nian + 1;?> & Yue = <? Php echo $ yue;?> "> Next year </a>
<! -- Flip the page of the month -->
<! -- Flip the page on the left -->
<A href = "? Yue = <? Php if ($ yue-1 <= 0) {echo '12';} else {echo $ yue-1;}?> & Nian = <? Php echo $ nian;?> ">
<? Php
If ($ yue-1 <= 0 ){
Echo '<'. '12 ';
} Else {
Echo '<'. ($ yue-1 );
}
?> Month
</A>
<! -- Right paging -->
<A href = "? Yue = <? Php if ($ yue + 1> 12) {echo '1';} else {echo $ yue + 1 ;}?> & Nian = <? Php echo $ nian;?> ">
<? Php
If ($ yue + 1> 12 ){
Echo '1 ';
} Else {
Echo $ yue + 1;
}?> Month & gt;
</A>
<! -- Form submission -->
<Form action = "01.php" method =" get ">
<P> year: <input type = "text" name = "nian"/> </p>
<P> month: <input type = "text" name = "yue"/> </p>
<Input type = "submit" value = "submit"/>
</Form>
</Td>
</Tr>
</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.