Php code for implementing the lunar calendar

Source: Internet
Author: User

Copy codeThe Code is as follows: php lunar calendar

<?
######################################## ###
# Author: Shen Yan (S & S Lab )#
# E-mail: shenlian@hotmail.com #
# Web: http://www.focus-2000.com #
##
# Copyright statement :#
# Copyright granted by the author #
# Allow unconditional use of all or part of this file #
# Any modifications or additions can be made #
# If you use this file, please write an email to the author #
# If you have any questions, contact the author #
# Thank you for your attention! #
######################################## ###

/*
* Modification: James
* Mail: san@xfocus.org
* Web: http://www.xfocus.org
*
* To be honest, I know nothing about the ancient calendar. The following array still does not understand, but the author's mailbox does not seem to be available.
* Basically, the image is like a gourd, so an error occurs.
*/

# Number of days of the lunar calendar month
$ Everymonth = array (
0 => array ),
1 => array ),
2 => array (, 3 ),
3 => array ),
4 => array ),
5 => array ),
6 => array ),
7 => array ),
8 => array ),
9 => array ),
10 => array ),
11 => array (6, 30, 29, 30, 29, 30, 29, 29, 29, 30, 29, 30, 30, 8, 12 ),
12 => array ),
13 => array ),
14 => array ),
15 => array ),
16 => array ),
17 => array (, 29,29, 30,29, 30,30, 29,30, 30,29, 30,29 ),
18 => array (, 29,29, 30,29, 30,29, 30,30, 29,30, 30,0, 5, 7 ),
19 => array ),
20 => array ),
21 => array ),
22 => array ),
23 => array ),
24 => array ),
25 => array ),
26 => array (, 3 ),
27 => array (, 29,29, 30,29, 30,29, 30,29, 30,30, 30,0 ),
28 => array ),
29 => array ),
30 => array (6, 29, 30, 30, 29, 30, 29, 29, 29, 30, 30, 29, 7 ),
31 => array ),
32 => array ),
33 => array (5, 29, 30, 30, 29, 30, 29, 30, 29, 29, 30, 10, 10 ),
34 => array ),
35 => array ),
36 => array (3,30, 29,29, 30,29, 29,30, 30,29, 30,30, 30,29, 3,1 ),
37 => array ),
38 => array ),
39 => array ),
40 => array ),
41 => array (6, 30, 30, 29, 30, 30, 29, 30, 29, 29, 29, 29, 8, 6 ),
42 => array ),
43 => array ),
44 => array ),
45 => array ),
46 => array ),
47 => array ),
48 => array ),
49 => array ),
50 => array ),
51 => array ),
52 => array (5, 29, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 9, 5 ),
53 => array ),
54 => array ),
55 => array ),
56 => array ),
57 => array ),
58 => array ),
59 => array ),
60 => array (6,30, 29,30, 29,30, 30,29, 30,29, 30,29, 30,29, 30,29, 7,1 ),
61 => array ),
62 => array ),
63 => array ),
64 => array ),
65 => array ),
66 => array ),
67 => array ),
68 => array ),
69 => array ),
70 => array (, 29,29, 30,29, 30,30, 29,30, 30,29, 30,0 ),
71 => array ),
72 => array ),
73 => array ),
74 => array ),
75 => array ),
76 => array (8, 30, 29, 30, 29, 30, 29, 30, 29, 29, 30, 3, 5 ),
77 => array ),
78 => array ),
79 => array (6, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29, 6, 8 ),
80 => array ),
81 => array ),
82 => array ),
83 => array (, 12 ),
84 => array ),
85 => array ),
86 => array (, 3 ),
87 => array (6, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 29, 4, 4 ),
88 => array ),
89 => array (, 29,29, 30,29, 29,30, 30,29, 30,30, 30,0, 6 ),
90 => array ),
91 => array ),
92 => array (, 30, 30, 29, 30, 29, 29, 29, 30, 30, 30, 0, 9, 9 ),
93 => array (, 10, 10 ),
94 => array ),
95 => array ),
96 => array ),
97 => array ),
98 => array ),
99 => array ),
100 => array ),
101 => array ),
102 => array ),
103 => array ),
104 => array ),
105 => array ),
106 => array ),
107 => array ),
108 => array ),
109 => array ),
110 => array ),
111 => array ),
112 => array ),
113 => array ),
114 => array (9,29, 30,29, 30,29, 30,29, 30,30, 29,30, 29,30 ),
115 => array ),
116 => array ),
117 => array ),
118 => array ),
119 => array ),
120 => array)
);
##############################
# Lunar calendar
$ Mten = array ("null", "A", "B", "C", "ding", "E", "Ji", "Geng ", "Xin", "shen", "Xi ");
# Lunar calendar
$ Mtwelve = array ("null", "Child (rat)", "ugly (COW)", "yin (TIGER)", "Mao (rabbit )", "Chen (Dragon )",
"Si (snake)", "Wu (Horse)", "Wei (Goat)", "Shen (monkey)", "You (chicken)", "Shen (DOG) "," Hai (pig )");
# Lunar month
$ Mmonth = array ("Hangzhou", "Zheng", "two", "three", "four", "five", "Six ",
"7", "8", "9", "10", "11", "12", "month ");
# Lunar calendar day
$ Mday = array ("null", "First Day", "Second Day", "Third Day", "fourth day", "Fifth Day", "Sixth Day", "Seventh Day ", "Eighth Day", "Ninth Day", "tenth day ",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20 ",
"Jun 1", "Jun 2", "Jun 3", "Jun 4", "Jun 5", "Jun 6", "Jun 7", "Jun 8 ", "9th", "30th ");
##############################
# Weeks
$ Weekday = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ");

# The total number of days of the Gregorian calendar to January 1, December 21, 1900
$ Total = 11;
# Total calendar days
$ Mtotal = 0;
##############################
# Obtain the date of the current day
$ Today = getdate ();
If ($ today ["year"] <1901 | $ today ["year"]> 2020) die ("year error! ");

$ Cur_wday = $ today ["wday"];

For ($ y = 1901; $ y <$ today ["year"]; $ y ++) {// calculate the total number of days of the expected date solar calendar-from January 1, December 21, 1900, calculate the sum of years
$ Total + = 365;
If ($ y % 4 = 0) $ total ++;
}

Switch ($ today ["mon"]) {// Add the month of the current year
Case 12:
$ Total + = 30;
Case 11:
$ Total + = 31;
Case 10:
$ Total + = 30;
Case 9:
$ Total + = 31;
Case 8:
$ Total + = 31;
Case 7:
$ Total + = 30;
Case 6:
$ Total + = 31;
Case 5:
$ Total + = 30;
Case 4:
$ Total + = 31;
Case 3:
$ Total + = 28;
Case 2:
$ Total + = 31;
}

If ($ today ["year"] % 4 = 0 & $ today ["mon"]> 2) $ total ++; // Add a day if the year is a leap year

$ Total = $ total + $ today ["mday"]-1; // Add the number of days in the current month

$ Flag1 = 0; // determine the condition for jumping out of the loop
$ J = 0;
While ($ j <= 120) {// use the number of days of the lunar calendar to accumulate to determine whether the number of days exceeds the number of days of the Gregorian calendar
$ I = 1;
While ($ I <= 13 ){
$ Mtotal + = $ everymonth [$ j] [$ I];
If ($ mtotal >=$ total ){
$ Flag1 = 1;
Break;
}
$ I ++;
}
If ($ flag1 = 1) break;
$ J ++;
}

If ($ everymonth [$ j] [0] <> 0 and $ everymonth [$ j] [0] <$ I) {// The original error is found here, and the leap month is not repaired.
$ Mm = $ I-1;
}
Else {
$ Mm = $ I;
}

If ($ I = $ everymonth [$ j] [0] + 1 and $ everymonth [$ j] [0] <> 0 ){
$ Nlmon = $ mmonth [0]. $ mmonth [$ mm]; # leap month
}
Else {
$ Nlmon = $ mmonth [$ mm]. $ mmonth [13];
}

# Calculate the lunar date of the Month 1
$ Md = $ everymonth [$ j] [$ I]-($ mtotal-$ total );
If ($ md> $ everymonth [$ j] [$ I])
$ Md-= $ everymonth [$ j] [$ I];
$ Nlday = $ mday [$ md];

$ Nowday = date ("Y, n, j "). $ weekday [$ cur_wday]. "<br> ". $ mten [$ everymonth [$ j] [14]. $ mtwelve [$ everymonth [$ j] [15]. "year ". $ nlmon. $ nlday;
Echo "<font color = # 3333ff> $ nowday </font> ";
?>

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.