PHP simple calendar implementation code

Source: Internet
Author: User
When I was writing a file system, I took a fancy to a foreign HTML template... there was a calendar on it and I wanted to write it out in PHP... The code is as follows:


$ Monthoneday = date ("Ym"). "01 ";
$ Oneweekday = date ("w", strtotime ($ monthoneday); // Obtain the day of the week from January 1, 1st day of this month.
$ Monthday = date ("t"); // The number of days of the month
$ Startlow = ($ oneweekday = 0 )? 7: $ oneweekday; // start from column number

For ($ a = 1, $ B = $ startlow; $ a <= $ monthday; $ a ++, $ B ++ ){
$ Ary [$ B] = $ a; // use arrays to control the output of dates.
}
$ C = 1;
// The number of output rows equals to the number of days in the current month, except 7 and then 1
For ($ a = 1; $ a <= (int) ($ monthday/7) + 1; $ a ++ ){
Echo "";
// I use the array key to control where to output the data.
For ($ B = 1; $ B <= 7; $ B ++, $ c ++ ){
If ($ ary [$ c] = date ("j ")){
Echo '';
} Else {
Echo "";
}
Echo $ ary [$ c];
Echo "";
Echo "\ n ";
}
Echo "";
}
?>


It is estimated that the writing method is different from that written by others... I have been writing this program for a long time. at the beginning, there was a problem with the loop idea. I actually output 31 lines and 1234 lines...
It seems that only multi-write can exercise thinking... this should be implemented using JS, but I won't be able to use JS... this is the only thing I can do.

The following figure shows the effect... the template is pretty nice...

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.