PHP output calendar table code example

Source: Internet
Author: User

PHP output calendar table code example

This article mainly introduces the PHP output calendar table code example. This article provides the code example directly. For more information, see

 

 

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<Html xmlns = "http://www.w3.org/1999/xhtml">

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>

<Title> calendar table </title>

<? Php

$ MONTH = array ("Lunar January", "January", "February", "March", "April", "May", "June", "July ", "May August", "May September", "May October", "May November", "May December ");

$ EnMONTH = array ("Lunar January", "January", "February", "Marcy", "Jun L", "May", "June", "July ", "August", "September", "October", "November", "December ");

$ WEEK = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ");

$ BACKCOLOR = array ("# FFC", "# FFF", "#9F6", "# FFC", "#6F0", "#6F6", "# F90 ", "# F06", "# F00", "# FC3", "# FF6", "# F99 ");

 

Function PrintMon ($ year, $ mon)

{

Date_default_timezone_set ("Asia/Shanghai ");

Global $ MONTH;

Global $ enMONTH;

Global $ WEEK;

Global $ BACKCOLOR;

 

$ Startdate = strtotime ("1 $ enMONTH [$ mon] $ year"); // obtain the year and month of the query.

$ Enddate = strtotime ("+ 1 month", $ startdate); // obtain the start date of the next month as the end time of the calendar output.

$ TheDate = getdate ($ startdate); // convert the date to the string format

$ Color = $ BACKCOLOR [$ mon]; // sets the background color of the calendar.

 

Echo ("<table border = \" 1 \ "cellspacing = \" 0 \ "cellpadding = \" 0 \ "bgcolor = \" $ color \ "> ");

$ Ym = $ year. "year". $ MONTH [$ mon];

Echo ("<caption>

Echo ("<tr> ");

For ($ I = 0; $ I <7; $ I ++) // outputs the day of the week

{

Echo ("<td width = \" 90 \ ", height = \" 40 \ "align = \" center \ "> ");

Echo ("

Echo ("</td> ");

}

Echo ("</tr> ");

 

 

$ TheWeek = $ theDate [wday]; // determines the day of the week.

For ($ I = 0; $ I <6; $ I ++)

{

Echo ("<tr> ");

For ($ j = 0; $ j <7; $ j ++)

{

Echo ("<td width = \" 90 \ ", height = \" 40 \ "align = \" center \ "> ");

If ($ startdate <$ enddate & $ theWeek = $ j) // output the date to the column of the corresponding day of the week, and be sure not to exceed the date of this month

{

$ TheDay = $ theDate [mday];

Echo ("

$ Startdate = strtotime ("+ 1 day", $ startdate); // one day before the date

$ TheDate = getdate ($ startdate); // update the date

$ TheWeek = ($ theWeek + 1) % 7; // update week

}

Echo ("</td> ");

}

Echo ("</tr> ");

If ($ startdate = $ enddate) // if all dates have been output, end the cycle

{

$ I = 6;

}

}

 

Echo ("</table ");

}

?>

 

 

</Head>

 

 

<Body>

 

 

<Form method = "post" action = "<? Php echo $ _ SERVER ['php _ SELF '];?> ">

<H1> enter the year and month to be viewed (the query range is January 1, January 1-20, 1970)

<Input type = "text" name = "myYear"> year <input type = "text" name = "myMonth"> month

<Input type = "submit">

</Form>

 

 

<? Php

$ Year = $ _ POST ['myyear'];

$ Month = $ _ POST ['mymonth'];

If (is_numeric ($ year) & $ year> = 1970 & $ year <2038)

{

If (is_numeric ($ month) & $ month >=1 & $ month <= 12)

{

PrintMon ($ year, $ month );

}

Else if ($ month! = NULL)

{

Echo ("the month is incorrect". "<br/> ");

}

}

Else if ($ year! = NULL)

{

Echo ("the year is incorrect". "<br/> ");

}

?>

 

 

</Body>

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.