PHP lunar calendar holiday

Source: Internet
Author: User
<? PHP/** lunar holidays */class lunar {var $ min_year = 1891; var $ max_year = 2100; var $ lunarinfo = array (Array ), array (,), array (), array (,), array, ), array ), array (,), array (,), array (,), ARRA Y (,), array (,), array (6, 1, 30,42200), array (,), array ), array (,), array (,), array, 28, 45656), array (, 16, 27216), array (,), array (,), array (0, 11104,), array (,), array, 17,54432), array (,), array ), array (,), array (,), array, 15, 46416), array (,), array () ,), Array ), array (,), array (,), array, 31,43344), array (,), array (,), array (), array ), array (,), array (,), array (, 21, 59696), array (,), array ), array (,), array (,), array, ), array ), array (,), array (,), 968), array (,), array ), array (,), array (,), array, ), array ), array (,), array (,), 6), array (,), array ), array (,), array (,), array (6, 1, 28,21176), array (, 16,21168), array (,), array ), array (,), array ), Array (,), array (,), array, 11,), array (,), array ), array (,), array (,), array, 10, 18864), array (,), Rray (,), array (,), array (8, 2, ), array ), array (,), array (,), array, 29,54440), array (, 17,54432), array (,), array (,), array (,), Array, 19,43344), array (, 46240), array (,), array ), array (,), array (,), array, 17,27296), array (,), array (0,), array (0, 42352,), array (,), array ), array (,), array (, rows), array (, rows), array, ), array (,), array )); /*** convert the Gregorian calendar to the Gregorian calendar * @ Param year Gregorian calendar-year * @ Param month Gregorian calendar-month * @ Param date Gregorian calendar-day */function convertsolartolunar ($ year, $ month, $ date ){// Debugger; $ yeardata = $ this-> lunarinfo [$ year-$ this-> min_year]; if ($ year = $ this-> min_year & $ month <= 2 & $ date <= 9) {return array (1891, 'October 11', '1e ', 'sinmao ', 'rabbit');} return $ this-> getlunarbybetween ($ year, $ this-> getdaysbetweensolar ($ year, $ month, $ date, $ yeardata [1], $ yeardata [2]);} function convertsolarmonthtolunar ($ year, $ month) {$ yeardata = $ this-> lunarinfo [$ year-$ this-> min_year]; if ($ year = $ this-> min_year & $ Month <= 2 & $ date <= 9) {return array (1891, 'february 11', '1st 1', 'sinmao ', lunar January, rabbit);} $ month_days_ary = array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); $ dd = $ month_days_ary [$ month]; if ($ this-> isleapyear ($ year) & $ month = 2) $ dd ++; $ lunar_ary = array (); For ($ I = 1; $ I <$ dd; $ I ++) {$ array = $ this-> getlunarbybetween ($ year, $ this-> getdaysbetweensolar ($ year, $ month, $ I, $ yeardata [1], $ yeardata [2]); $ array [] = $ Year. '-'. $ month. '-'. $ I; $ lunar_ary [$ I] = $ array;} return $ lunar_ary ;} /*** convert the lunar calendar to the Gregorian calendar * @ Param year-year * @ Param month indicates the lunar calendar-month, And the leap month is processed. For example, if the current year expires on January 1, May, in this case, the second month is set to 13th, which is equivalent to 13 months in the lunar calendar, but sometimes the number of days in the second month is 0 * @ Param date in the lunar calendar-day */function convertlunartosolar ($ year, $ month, $ date) {$ yeardata = $ this-> lunarinfo [$ year-$ this-> min_year]; $ between = $ this-> getdaysbetweenlunar ($ year, $ month, $ date); $ res = mktime (0, 0, 0, $ y Eardata [1], $ yeardata [2], $ year); $ res = Date ('Y-m-d ', $ res + $ between * 24*60*60); $ day = explode ('-', $ res); $ year = $ day [0]; $ month = $ day [1]; $ day = $ day [2]; return array ($ year, $ month, $ day );} /*** determine whether it is a leap year * @ Param year */function isleapyear ($ year) {return ($ year % 4 = 0 & $ year % 100! = 0) | ($ year % 400 = 0);}/*** obtain the year of the credit calculation * @ Param year */function getlunaryearname ($ year) {$ Sky = array ('geng ', 'sin', 'shen', 'cap', 'A', 'B', 'bing', 'ding ', 'pente', 'jid'); $ Earth = array ('shen', 'uni', 'shanghai', 'sub', 'ug ', 'yin ', 'mao', 'chen ', 'si', 'wu ', 'wei'); $ year = $ year. ''; return $ sky [$ year {3}]. $ Earth [$ year % 12];}/*** obtain the zodiac sign based on the lunar year * @ Param year lunar year */function getyearzodiac ($ year) {$ Zodiac = array ('Monkey ', 'chicken', 'Dog', 'pig', 'rat ', 'ox', 'tiger ', 'rabbit ', 'long', 'snake ', 'Ma', 'yang' ); Return $ Zodiac [$ year % 12];} /*** get the number of days of the calendar month * @ Param year Gregorian calendar-year * @ Param month Gregorian calendar-month */function getsolarmonthdays ($ year, $ month) {$ monthhash = array ('1' => 31, '2' => $ this-> isleapyear ($ year )? 29:28, '3' => 31, '4' => 30, '5' => 31, '6' => 30, '7' => 31, '8' => 31, '9' => 30, '10' => 31, '11' => 30, '12' => 31 ); return $ monthhash ["$ month"];}/*** get the number of days of the calendar month * @ Param year lunar calendar-year * @ Param month Lunar Calendar-month, starting from January 1, January */function getlunarmonthdays ($ year, $ month) {$ monthdata = $ this-> getlunarmonths ($ year); return $ monthdata [$ month-1];} /*** get the array of the number of days of the calendar month * @ Param year */function getlunarmonths ($ year) {$ yeardata = $ this-> lunarinfo [$ y Ear-$ this-> min_year]; $ leapmonth = $ yeardata [0]; $ bit = decbin ($ yeardata [3]); For ($ I = 0; $ I <strlen ($ bit); $ I ++) {$ bitarray [$ I] = substr ($ bit, $ I, 1 );} for ($ k = 0, $ klen = 16-count ($ bitarray); $ k <$ klen; $ K ++) {array_unshift ($ bitarray, '0') ;}$ bitarray = array_slice ($ bitarray, 0, ($ leapmonth = 0? 12: 13); For ($ I = 0; $ I <count ($ bitarray); $ I ++) {$ bitarray [$ I] = $ bitarray [$ I] + 29;} return $ bitarray ;} /*** get the number of days of the lunar calendar year * @ Param year */function getlunaryeardays ($ year) {$ yeardata = $ this-> lunarinfo [$ year-$ this-> min_year]; $ montharray = $ this-> getlunaryearmonths ($ year ); $ Len = count ($ montharray); Return ($ montharray [$ len-1] = 0? $ Montharray [$ len-2]: $ montharray [$ len-1]);} function getlunaryearmonths ($ year) {// debugger; $ monthdata = $ this-> getlunarmonths ($ year ); $ res = array (); $ temp = 0; $ yeardata = $ this-> lunarinfo [$ year-$ this-> min_year]; $ Len = ($ yeardata [0] = 0? 12: 13); For ($ I = 0; $ I <$ Len; $ I ++) {$ temp = 0; For ($ J = 0; $ j <= $ I; $ J ++) {$ temp + = $ monthdata [$ J];} array_push ($ res, $ temp);} return $ res ;} /*** get a leap month * @ Param year lunar year */function getleapmonth ($ year) {$ yeardata = $ this-> lunarinfo [$ year-$ this-> min_year]; return $ yeardata [0];}/*** calculate the number of days between the lunar calendar date and January 1, lunar January 1 * @ Param year * @ Param month * @ Param date */function getdaysbetweenlunar ($ year, $ month, $ date) {$ yearmonth = $ This-> getlunarmonths ($ year); $ res = 0; For ($ I = 1; $ I <$ month; $ I ++) {$ res + = $ yearmonth [$ I-1];} $ res + = $ date-1; return $ res ;} /*** calculate the number of days between two calendar dates * @ Param year calendar year * @ Param cmonth * @ Param cdate * @ Param dmonth the calendar month corresponding to January 1, lunar January * @ Param ddate the number of calendar days corresponding to the first day */function getdaysbetweensolar ($ year, $ cmonth, $ cdate, $ dmonth, $ ddate) {$ A = mktime (0, 0, $ cmonth, $ cdate, $ year); $ B = mktime (0, 0, 0, $ dmonth, $ ddate, $ year); Re Turn Ceil ($ A-$ B)/24/3600 );} /*** calculate the lunar calendar date by the number of days from January 1, lunar January 1 * @ Param year/function getlunarbybetween ($ year, $ between) {// debugger; $ lunararray = array (); $ yearmonth = array (); $ T = 0; $ e = 0; $ leapmonth = 0; $ M = ''; if ($ between = 0) {array_push ($ lunararray, $ year, 'August 1', '1n1'); $ T = 1; $ e = 1 ;} else {$ year = $ between> 0? $ Year: ($ year-1); $ yearmonth = $ this-> getlunaryearmonths ($ year); $ leapmonth = $ this-> getleapmonth ($ year ); $ between = $ between> 0? $ Between: ($ this-> getlunaryeardays ($ year) + $ between); For ($ I = 0; $ I <13; $ I ++) {if ($ between = $ yearmonth [$ I]) {$ T = $ I + 2; $ e = 1; break ;} else if ($ between <$ yearmonth [$ I]) {$ T = $ I + 1; $ e = $ between-(empty ($ yearmonth [$ I-1])? 0: $ yearmonth [$ I-1]) + 1; break ;}}$ M = ($ leapmonth! = 0 & $ T = $ leapmonth + 1 )? ('Authorization'. $ this-> getcapitalnum ($ t-1, true): $ this-> getcapitalnum ($ leapmonth! = 0 & $ leapmonth + 1 <$ t? ($ T-1): $ T), true); array_push ($ lunararray, $ year, $ M, $ this-> getcapitalnum ($ E, false ));} array_push ($ lunararray, $ this-> getlunaryearname ($ year); // array_push ($ lunararray, $ T, $ E); array_push ($ lunararray, $ this-> getyearzodiac ($ year); // 12 zodiac array_push ($ lunararray, $ leapmonth); // returns $ lunararray ;} /*** obtain the digit's lunar name * @ Param num Number * @ Param ismonth is the number of the month */function getcapitalnum ($ num, $ ismonth) {$ Ismonth = $ ismonth | false; $ datehash = array ('0' => '', '1' => '1 ', '2' => '2', '3' => '3', '4' => '4', '5' => '5 ', '6' => '6', '7' => '7', '8' => '8', '9' => '9 ', '10' => '10'); $ monthhash = array ('0' => '', '1' => 'August 1 ', '2' => 'August 11', '3' => 'August 11', '4' => 'August 11', '5' => 'August 11 ', '6' => 'August 11', '7' => 'August 11', '8' => 'August 11', '9' => 'August 11 ', '10' => 'August 11', '11' => 'August 11', '12' => 'August 11'); $ res = ''; if ($ ismonth) {$ res = $ monthhash [$ num];} else {if ($ num <= 10) {$ res = 'chu '. $ datehash [$ num];} el Se if ($ num> 10 & $ num <20) {$ res = '10 '. $ datehash [$ num-10];} else if ($ num = 20) {$ res = "20";} else if ($ num> 20 & $ num <30) {$ res = "Hangzhou ". $ datehash [$ num-20];} else if ($ num = 30) {$ res = "Thirty" ;}} return $ res ;} /** common solar term algorithm */function getjieqi ($ _ year, $ month, $ day) {$ year = substr ($ _ year,-2) + 0; $ coefficient = array (Array (5.4055, 2019,-1), // small cold array (20.12, 2082,1), // large cold array (3.87), // early spring array (18.74, 2026,-1), // rain array (5.6 3), // shocking array (20.646, 4.81, 20.1), // spring minute array (5.52), // clear array (), // grain rain array (, 1 ), // summer array (21.04, 5.678), // small full array (21.37, 7.108,), // grain array (,), // summer to array ), // heatmap array (22.83, 7.5, 23.13), // heatmap array (7.646,), // autumn array (), // heatmap array ), // White Dew array (23.042, 8.318, 23.438), // autumn equinox array (7.438), // Cold Dew array (, 1), // Frost descent array (, 1 ), // winter array (22.36, 7.18, 1954), // light snow array (,, 1), // snow array (21.94, 2021,-1) // winter solstice); $ term_name = array ("Xiao Han", "da Han", "Li Chun ", "Rain", "stunned", "Spring Equinox", "Qingming Festival", "grain rain", "Summer", "grain", "grain", "Summer Solstice", "Summer heat ", "Great heat", "Autumn", "Summer heat", "White Dew", "Autumn Equinox", "Cold Dew", "Frost fall", "Winter", "light snow", "heavy snow ", "Winter Solstice"); $ idx1 = ($ month-1) * 2; $ _ leap_value = floor ($ year-1)/4 ); $ day1 = floor ($ year * 0.2422 + $ coefficient [$ idx1] [0])-$ _ leap_value; If (isset ($ coefficient [$ idx1] [1]) & $ coefficient [$ idx1] [1] === _ year) {$ day1 + = $ coefficient [$ idx1] [2];} $ day2 = Floor ($ year * 0.2422 + $ coefficient [$ idx1 + 1] [0])-$ _ leap_value; if (isset ($ coefficient [$ idx1 + 1] [1]) & $ coefficient [$ idx1 + 1] [1] === _ year) {$ day1 + = $ coefficient [$ idx1 + 1] [2];} // echo _ file __. '-> '. _ line __. '$ day1 = '. $ day1, ', $ day2 = '. $ day2. '<br/> '. CHR (10); if ($ day = $ day1) return $ term_name [$ idx1]; if ($ day = $ day2) return $ term_name [$ idx1 + 1]; return '';}/** get Festival: this function can only be modified for special festivals. */function getfestival ($ today, $ NL _ Info = false, $ Config = 1) {if ($ Config = 1) {$ arr_lunar = array ('01-01 '=> 'spring festival ', '01-15' => 'lantern festival ', '02-02' => 'August 1', '05-05 '=> 'Dragon Boat Festival ', '07-07 '=> 'qixi Day', '08-15' => 'mid-autumn festival', '09-09' => 'chongyang Day ', '12-08' => 'labarba', '12-23' => 'small year'); $ arr_solar = array ('01-01 '=> 'new year ', '02-14' => 'valentine's Day', '03-12' => 'tree planting Day', '04-01 '=> 'fools ', '05-01' => 'Labor Day', '06-01 '=> 'children's Day', '10-01' => 'National Day ', '10-31' => 'Halloween ', '12-24' => 'Christmas Eve ', '12-25' => 'Christmas ');} // for different festivals, use different $ config and configure $ arr_lunar and $ Arr_solar $ festivals = array (); List ($ y, $ M, $ d) = explode ('-', $ today); If (! $ Nl_info) $ nl_info = $ this-> convertsolartolunar ($ y, intval ($ m), intval ($ D )); if ($ nl_info [7]> 0 & $ nl_info [7] <$ nl_info [4]) $ nl_info [4]-= 1; $ md_lunar = substr ('0 '. $ nl_info [4],-2 ). '-'. substr ('0 '. $ nl_info [5],-2); $ md_solar = substr_replace ($ today, '', 0, 5); isset ($ arr_lunar [$ md_lunar])? Array_push ($ festivals, $ arr_lunar [$ md_lunar]): ''; isset ($ arr_solar [$ md_solar])? Array_push ($ festivals, $ arr_solar [$ md_solar]): ''; $ glweek = date (" W ", strtotime ($ today )); // 0-6 if ($ M = 5 & ($ D> 7) & ($ d <15) & ($ glweek = 0 )) array_push ($ festivals, "Mother's Day"); if ($ M = 6 & ($ D> 14) & ($ d <22) & ($ glweek = 0) array_push ($ festivals, "Father's Day"); $ Jieqi = $ this-> getjieqi ($ y, $ M, $ D ); if ($ Jieqi) array_push ($ festivals, $ Jieqi); Return implode ('/', $ festivals );}}

 

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.