Php solar to lunar optimized version, php solar lunar Optimization
The examples in this article share the php solar calendar to Lunar Calendar code for your reference. The details are as follows:
<? Php function nongli ($ riqi) {// optimized modification 20160807 FXL $ nian = date ('y', strtotime ($ riqi); $ yue = date ('M ', strtotime ($ riqi); $ ri = date ('D', strtotime ($ riqi); # source code: Shen Yu (S & S Lab) # Days of the lunar calendar month $ everymonth = array (0 => array (,), 1 => array, 30,29, 29,30, 29,30, 29,30, 30,30, 29,0,), 2 => array (, 29,30, 29,29, 30,29, 30,29, 30,30, 30,0, 9,3 ), 3 => array (5, 29, 30, 29, 30, 29, 29, 30, 29, 29, 29, 30, 29, 30, 10, 4), 4 => array (, 29, 29,), 5 => array (, 30, 30, 30, 30, 30, 30, 29, 29, 29, 30, 29, 30, 29, 30, 29, 30, 29, 29, 30,29, 30,0,), 6 => array (, 30,30, 29,30, 29,30, 29,30, 29,30, 29,30,), 7 => array (, 30,29, 30,29, 30,29, 29, 30,30, 29,30, 29,30, 29,30, 29,0,), 8 => array (, 29,29, 30,30, 29,30, 29,30, 30,29, 30,0, 5, 9), 9 => array (, 29, 30,29, 29,30, 29,30, 29,30, 30,30, 29,30, 6,10), 10 => array (, 30,29, 29,30, 29,30, 29,30, 29,30, 30,30, 29,0 ), 11 => ar Ray (6,30, 29,30, 29,29, 30,29, 29,30, 30,30, 8,12), 12 => array (, 29,30, 29,30, 29,29, 30,29, 29,30, 30,29, 30,0, 9, 1), 13 => array (, 30, 29, 30, 29, 29, 29, 29, 29, 30, 29, 30, 0, 10, 2), 14 => array (, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30,29, 29,30,), 15 => array (, 29,30, 30,29, 30,29, 30,29, 30,29, 30,0,), 16 => array (, 30,29, 30,29, 30,29, 30,30, 29,30, 29,30, 29,30, 29,0, 3,5), 17 => array (, 29,29, 30,29, 30,30, 29,30, 30,29, 30,29,), 18 => array (, 29,29, 30,29, 30,29, 30,29, 30,30, 29,30, 30,0,), 19 => array (, 30,29, 29,30, 29,29, 30,30, 29,30 ), 20 => array (,), 21 => array, 30,0,), 22 => array (, 29,30, 30,29, 29,30, 29,29, 30,29, 30,30, 9,11), 23 => array (, 30,30, 29,30, 29,30, 29,30, 30, 29,29, 30,29, 30,0, 10,12), 24 => array (, 30,30, 29,30, 30,29, 30,29, 30,29, 29,0,), 25 => array (4, 30,29, 30,29, 30,30, 29,30, 30,29, 30,29, 30,2, 26 => array (, 29,30, 29,30, 29,30, 29,30, 30,29, 30,30, 29,0, 3,3 ), 27 => array (, 29,29, 30,29, 30,29, 30,29, 30,30, 30,0,), 28 => array (, 30,29, 29,30, 29,29, 30,30, 30,30, 5), 29 => array (, 30,29, 29,30, 29,29, 30,29, 30,30, 30,0, 6,6), 30 => array (, 30,30, 29,29, 30,29, 30,29, 29,30, 29,30, 30,29, 7,7), 31 => array (, 30,29, 30,29, 30,29, 29,30, 29,30, 29,30, 29,0,), 32 => array (, 3 ,), 33 => array ), 34 => array (, 30, 30,), 35 => array (, 30,), 35 => array (, 30, 30, 30, 29,0,), 36 => array (3,30, 29,29, 30,29, 29,30, 30,29, 30,30, 30,29, 3,1), 37 => array (, 29,29, 30,29, 29,30, 29,30, 29,30, 30,30, 29,0, 4,2), 38 => array (, 30,29, 29,30, 29,29, 30,29, 30,30, 29,30, 5, 3), 39 => array (, 30), 29,29, 30,29, 29,30, 29,30, 29,30, 4), 40 => array (, 30,29, 30,29, 30,29, 29,30, 29,30, 29,0, 7,5 ), 41 => array (6, 30, 29, 30, 30, 29,30, 29,29, 30,29, 30,29,), 42 => array (, 29,30, 30,29, 30,29, 30,29, 30,29, 30,29, 30,0, 9,7), 43 => array (, 30,29, 30,29, 30,30, 29,30, 29,30, 29,0, 10,8), 44 => array (, 29,30, 29,30, 29,30, 29,30, 29,30, 30,29, 30,30,), 45 => array (, 29,30, 29,29, 30,29, 30,30, 30,29, 30,0,), 46 => array (, 29,29, 29, 29, 30,29, 29,30, 29,30, 30,29, 30,0, 3,11), 47 => array (, 30,29, 29,30, 29,29, 30,29, 30,29, 30,30 ), 48 => array (,), 49 => array, 29,30, 6,2), 50 => array (, 30,), 51 => array (,), 51 => array (, 29, 29, 30,29, 30,29, 30,0,), 52 => array (, 30,29, 30,29, 30,29, 30,29, 30,30, 29,30, 29,30, 9,5), 53 => array (, 30,29, 29, 29, 30,30, 29,30, 30,29, 30,29, 6), 54 => array (, 29,30, 29,29, 30,29, 30,30, 29,30, 30,0 ), 55 => array (,), 56 => array, 30, 0,), 57 => array (,), 58 => array (, 30, 30,), 58 => array (, 30, 30, 29, 29, 29, 29, 30,29, 30,29, 30,0,), 59 => array (, 30,30, 29,30, 29,30, 29,30, 29,30, 29,30, 29,0, 6,12), 60 => array (, 29,30, 29,30, 30,29, 30,29, 30,29, 30,29, 7,1), 61 => array (, 29,30, 29,30, 29,30, 30,29, 30,29, 30,29, 30,0 ), 62 => array (,), 63 => array (, 30, 30, 30, 30, 30,29, 10,4), 64 => array (, 29,30, 29,29, 30,29, 30,29, 30,29, 30,30, 30,0,), 65 => array (, 30,29, 30,29, 29,30, 29,29, 30,30, 29,0,), 66 => array (, 30, 30, 29,30, 29,30, 29,29, 30,29, 29,30, 30,29,), 67 => array (, 30,29, 29, 30, 30, 29, 29,30, 29,30, 29,30, 8), 68 => array (7,29, 30,29, 30,30, 29,30, 29,30, 29,30, 29,30,), 69 => array, 30,29, 30,29, 30,30, 29,30, 29,30, 29,0, 6,10), 70 => array (, 29,29, 30,29, 30,30, 29,30, 30,29, 30,0 ), 71 => array (,), 72 => array (, 30, 30, 30, 30,0, 9,1), 73 => array (, 29,30, 29,29, 30,29, 29,30, 30,29, 30,0, 10,2), 74 => array (, 30,29, 30,29, 30,29, 29,30, 29,29, 30,30, 29,30,), 75 => array (, 30,29, 30,29, 29,30, 29,29, 30,29, 30,0,), 76 => array, 30,29, 30,29, 30,29, 30,29, 29,30, 29,30, 3,5), 77 => array (, 29,30, 30,29, 30,29, 30,29, 30,29, 30,29, 29,0 ), 78 => array (,), 79 => array (, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 29, 29, 30,29, 6,8), 80 => array (, 29,29, 30,29, 30,29, 30,30, 29,30, 30,0,), 81 => array (, 30,29, 29,30, 29,29, 29,29, 29, 29, 30,3, 30, 30, 10), 82 => array (, 29, 29, 29, 29, 29, 29, 30, 30, 30, 9, 11), 83 => array, 29,29, 30,29, 29,30, 29,30, 30,0, 10,12), 84 => array (10 ,30, 29,30, 30,29, 29,30, 29,29, 30,29, 30,30 ), 85 => array (, 30, 30,), 86 => array (, 30, 30, 30,), 86 => array (, 30, 30, 30, 30, 29, 30, 29, 30, 30, 29, 29,0,), 87 => array (, 29,30, 29,30, 30,29, 30,30, 29,30, 29,29,), 88 => array (, 29,30, 29,30, 29,30, 29,30, 29,30, 30,2 9,30, 30,29, 5), 89 => array (, 29,29, 30,29, 29,30, 30,29, 30,30, 30,0, 6,6), 90 => array, 29,30, 29,29, 30,29, 30,30, 30,30, 7,7), 91 => array (, 30,29, 29,30, 29,29, 30,29, 30,30, 30,0 ), 92 => array (, 30, 30, 29,29, 30,29, 29,30, 29,30, 30,0, 9,9), 93 => array (, 30,30, 29,30, 29,30, 29,29, 29,29, 30,29, 30,29, 10,10), 94 => array (, 30,30, 29,30, 29,30, 29,29, 30,29, 30,0,), 95 => array (, 30,30, 29,30, 29,30, 29,30, 30, 30,29, 2 9, 30, 29, 30,), 96 => array (, 30, 29, 30, 30, 29, 30, 29, 30, 30, 30, 29, 0, 3, 1), 97 => array (, 30, 29,30, 30,29, 30,30, 29,0,), 98 => array (, 29,29, 30,29, 29,30, 30,29, 30,30, 29,30, 5, 3), 99 => array (, 30, 29,29, 30,29, 29,30, 29,30, 30,30, 29,0, 6,4), 100 => array (, 30,29, 29,30, 29,29, 30,29, 30,30, 29,0, 7,5 ), 101 => array (102,), => array (, 29, 29, 29, 29, 29, 29, 29, 103, 29, 104, 7), => array (,), => array, 30,30, 29,30, 29,30, 29,30, 29,30, 105), => array (, 30,29, 30,29, 30,30, 29,30, 29,30, 29,30, 29,0 ), 106 => array (107,), => array, 30,0, 108), 109 => array (, 29,29, 30,29, 29,30, 29,30, 30,29, 30,0,), => array (, 30,29, 29,30, 29,30, 29,29, 29, 29, 30, 29,30, 29,30, 30,6, 2), 110 => array (111, 29,30, 29,30, 29,30, 29,29, 30,29, 30,0, 7,3), => array (, 29,30, 30,29, 30,29, 29,30, 29,30, 29,0, 112), => array (, 29,30, 30,29, 30,29, 30,29, 30,29, 30,29, 30,29, 9,5 ), 113 => array (114,), => array, 29,30, 115), 116 => array (, 30,29, 29,30, 29,30, 30,30, 29,30, 29,0,), => array (, 29,30, 29,29, 30,29, 30,29, 30,30, 29,30, 30,0, 3,9), 117 => array (6, 29, 30,29, 30,29, 29,30, 29,30, 29,30, 30,30, 118), => array (, 30,29, 29, 30,29, 29,30, 29,30, 29,30, 30,0, 5, 11), 119 => array (, 29,30, 29,30, 29,29, 30,29, 29,30, 30,0, 6, 12 ), 120 => array )); ############################# $ $ mten = array ("null ", "A", "B", "C", "ding", "Wu", "Ji", "Geng", "Xin", "shen ", ""); # $ mtwelve = array ("null", "Child (rat)", "ugly (OX)", "Yin (TIGER) "," Mao (rabbit) "," Chen (Dragon) "," Si (snake) "," Wu (Horse) "," Wei (Goat )", "Shen (monkey)", "You (chicken)", "Yellow (DOG)", "Hai (pig )"); # lunar month $ mmonth = array ("Hangzhou", "Zheng", "two", "three", "four", "five", "Six", "Seven ", "8", "9", "10", "11", "12", "month"); # lunar 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 "); ############################# week $ weekday = array ("Sunday", "Monday", "Tuesday ", "Wednesday", "Thursday", "Friday", "Saturday"); # The total number of calendar days to December 21, 1900 $ total = 11; # The total number of calendar days $ mtotal = 0; ############################# obtain the date of the current day // $ today = getdate (); // get today's date if ($ nian <1901 | $ nian> 2020) die ("year error! "); // $ Cur_wday = $ today [" wday "]; // The number of the day of the week indicates for ($ y = 1901; $ y <$ nian; $ y ++) {// calculate the total number of days of the expected date solar calendar-from January 1, December 21, 1900, calculate the sum of the year and $ total + = 365; if ($ y % 4 = 0) $ total ++;} switch ($ yue) {// Add the case 12: $ total + = 30 of the year; 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 ($ nian % 4 = 0 & $ yue> 2) $ total ++; // If the year is a leap year plus a day $ total = $ total + $ ri-1; // Add the day of the month $ flag1 = 0; // determine the condition for jumping out of the cycle $ j = 0; while ($ j <= 120) {// use the number of days accumulated in the lunar calendar to determine whether the number of days exceeds the number of days in 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, $ mm = $ I-1;} else {$ mm = $ I;} not patched for a leap month ;} 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 for the first day of the month. $ md = $ everymonth [$ j] [$ I]-($ mtotal-$ total ); if ($ md> $ everymonth [$ j] [$ I]) $ md-= $ everymonth [$ j] [$ I]; $ nlday = $ mday [$ md]; // $ nowday = date ("Y, n, j "). "w ". $ weekday [$ cur_wday]. "". $ mten [$ everymonth [$ j] [14]. $ mtwelve [$ everymonth [$ j] [15]. "year ". $ nlmon. $ nlday; $ nowday = $ mten [$ everymonth [$ j] [14]. $ mtwelve [$ everymonth [$ j] [15]. "year ". $ nlmon. $ nlday; return $ nowday;} echo nongli ('000000'); // Standard 8-bit
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.