Php simple calendar functions

Source: Internet
Author: User
This article mainly introduces the php simple calendar function. instead of selecting a common calendar generated using js, it outputs a calendar table using php, interested friends can refer to the example in this article to describe the calendar program implemented by php. Share it with you for your reference. The details are as follows:

<? Php/** php output calendar program */header ("Content-type: text/html; charset = utf-8"); $ year = (! Isset ($ _ GET ['Year']) | $ _ GET ['Year'] = "")? Date ("Y"): $ _ GET ['Year']; $ month = (! Isset ($ _ GET ['month']) | $ _ GET ['month'] = "")? Date ("n"): $ _ GET ['month']; $ curUrl = $ _ SERVER ['php _ SELF ']; if ($ year <1971) {echo "error! "; Echo"
"; Echo" Back "; exit () ;}?>";}Else {$ FontStyle =" ";}return $ FontStyle ;}for ($ I = 0; $ I <=$ FirstDay; $ I ++) {// this for is used to output location 1 of a month for ($ I; $ I <$ FirstDay; $ I ++) {echo"\ N ";}if ($ I ==$ FirstDay) {echo"\ N "; if ($ FirstDay = 6) {// judge whether the first day is Saturday echo"";}}$ CountMonth = date (" t ", mktime (0, 0, $ month, 1, $ year )); // The total number of days of a month for ($ I = 2; $ I <= $ countMonth; $ I ++) {// The output is located on the first day, echo"\ N "; if (date (" w ", mktime (0, 0, $ month, $ I, $ year) = 6) {// Determine whether the day is Saturday echo"\ N ";}}?> <? Php $ d = date ("d"); $ FirstDay = date ("w", mktime (0, 0, $ month, 1, $ year )); // Obtain the number one of the week in any month. the number one is calculated starting from the number of cells in the table. $ bgtoday = date ("d"); function font_color ($ month, $ today, $ year) {// used to calculate the font color of Sunday $ Sunday = date ("w", mktime (, 0, $ month, $ today, $ year); if ($ Sunday = "0") {$ FontColor = "red";} else {$ FontColor = "black";} return $ FontColor ;} function bgcolor ($ month, $ bgtoday, $ today_ I, $ year) {// calculate the background color of the day $ show_today = date ("d", mktime (, 0, 0, $ month, $ today_ I, $ year); $ sys_today = date ("d", mktime (0, 0, 0, $ month, $ bgtoday, $ year )); if ($ show_today ==$ sys_today) {$ bgcolor = "bgcolor = # 6699FF" ;}else {$ bgcolor = "" ;}return $ bgcolor ;} function font_style ($ month, $ today, $ year) {// calculate the font style of Sunday $ Sunday = date ("w", mktime (, 0, $ month, $ today, $ year); if ($ Sunday = "0") {$ FontStyle ="
<? Php // <------- processing when the month exceeds 1 to 12; start -------> if ($ month <1) {$ month = 12; $ year-= 1 ;} if ($ month> 12) {$ month = 1; $ year + = 1 ;}// <------- processing when the month exceeds 1 to 12; end -------> // <--------- connection processing and output for the previous year, next year, last month, and next month; start ---------> echo "< <年> > ";?> <? Php echo $ year. "year". $ month. "month";?> <? Php echo "< <月> > "; // <-------- Connection processing and output for the previous year, next year, last month, and next month; end --------- >?>
Day I II 3. Thu V. Sat.
". Font_style ($ month, 1, $ year)." 1
". Font_style ($ month, $ I, $ year)." $ I

The calendar output by php is as follows:

I hope this article will help you learn about php programming.

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.