国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

php 根據(jù)生日計算星座和生肖程序

2020-03-22 18:41:18
字體:
來源:轉載
供稿:網(wǎng)友

一個php 根據(jù)生日計算星座和生肖程序,有需要的朋友可參考參考.

魔羯座(12/22 – 1/19)、水瓶座(1/20 – 2/18)、雙魚座(2/19 – 3/20)、牡羊座(3/21 – 4/20)、金牛座(4/21 – 5/20)、雙子座(5/21 – 6/21)、巨蟹座(6/22 – 7/22)、獅子座(7/23 – 8/22)、處女座(8/23 – 9/22)、天秤座(9/23 – 10/22)、天蝎座(10/23 – 11/21)、射手座(11/22 – 12/21)

PHP實例代碼如下:

  1. /**
  2. *getConstellation根據(jù)出生生日取得星座
  3. *
  4. *@paramString$brithday用于得到星座的日期格式為yyyy-mm-dd
  5. *
  6. *@paramArray$format用于返回星座的名稱
  7. *
  8. *@returnString
  9. */
  10. functiongetConstellation($birthday,$format=null)
  11. {
  12. $pattern=‘/^d{4}-d{1,2}-d{1,2}$/’;
  13. if(!preg_match($pattern,$birthday,$matchs))
  14. {
  15. returnnull;
  16. }
  17. $date=explode(‘-’,$birthday);
  18. $year=$date[0];
  19. $month=$date[1];
  20. $day=$date[2];
  21. if($month<1||$month>12||$day<1||$day>31)
  22. {
  23. returnnull;
  24. }
  25. //設定星座數(shù)組
  26. $constellations=array(
  27. ‘摩羯座’,‘水瓶座’,‘雙魚座’,‘白羊座’,‘金牛座’,‘雙子座’,
  28. ‘巨蟹座’,'獅子座’,‘處女座’,‘天秤座’,‘天蝎座’,‘射手座’,);
  29. //或‍‍$constellations=array(
  30. ‘Capricorn’,‘Aquarius’,‘Pisces’,‘Aries’,‘Taurus’,‘Gemini’,
  31. ‘Cancer’,'Leo’,‘Virgo’,‘Libra’,‘Scorpio’,‘Sagittarius’,);
  32. //設定星座結束日期的數(shù)組,用于判斷
  33. $enddays=array(19,18,20,20,20,21,22,22,22,22,21,21,);
  34. //如果參數(shù)format被設置,則返回值采用format提供的數(shù)組,否則使用默認的數(shù)組
  35. if($format!=null)
  36. {
  37. $html' target='_blank'>values=$format;
  38. }
  39. else
  40. {
  41. $values=$constellations;
  42. }
  43. //根據(jù)月份和日期判斷星座
  44. switch($month)
  45. {
  46. case1:
  47. if($day<=$enddays[0])
  48. {
  49. $constellation=$values[0];
  50. }
  51. else
  52. {
  53. $constellation=$values[1];
  54. }
  55. break;
  56. case2:
  57. if($day<=$enddays[1])
  58. {
  59. $constellation=$values[1];
  60. }
  61. else
  62. {
  63. $constellation=$values[2];
  64. }
  65. break;
  66. case3:
  67. if($day<=$enddays[2])
  68. {
  69. $constellation=$values[2];
  70. }
  71. else
  72. {
  73. $constellation=$values[3];
  74. }
  75. break;
  76. case4:
  77. if($day<=$enddays[3])
  78. {
  79. $constellation=$values[3];
  80. }
  81. else
  82. {
  83. $constellation=$values[4];
  84. }
  85. break;
  86. case5:
  87. if($day<=$enddays[4])
  88. {
  89. $constellation=$values[4];
  90. }
  91. else
  92. {
  93. $constellation=$values[5];
  94. }
  95. break;
  96. case6:
  97. if($day<=$enddays[5])
  98. {
  99. $constellation=$values[5];
  100. }
  101. else
  102. {
  103. $constellation=$values[6];
  104. }
  105. break;
  106. case7:
  107. if($day<=$enddays[6])
  108. {
  109. $constellation=$values[6];
  110. }
  111. else
  112. {
  113. $constellation=$values[7];
  114. }
  115. break;
  116. case8:
  117. if($day<=$enddays[7])
  118. {
  119. $constellation=$values[7];
  120. }
  121. else
  122. {
  123. $constellation=$values[8];
  124. }
  125. break;
  126. case9:
  127. if($day<=$enddays[8])
  128. {
  129. $constellation=$values[8];
  130. }
  131. else
  132. {
  133. $constellation=$values[9];
  134. }
  135. break;
  136. case10:
  137. if($day<=$enddays[9])
  138. {
  139. $constellation=$values[9];
  140. }
  141. else
  142. {
  143. $constellation=$values[10];
  144. }
  145. break;
  146. case11:
  147. if($day<=$enddays[10])
  148. {
  149. $constellation=$values[10];
  150. }
  151. else
  152. {
  153. $constellation=$values[11];
  154. }
  155. break;
  156. case12:
  157. if($day<=$enddays[11])
  158. {
  159. $constellation=$values[11];
  160. }
  161. else
  162. {
  163. $constellation=$values[0];
  164. }
  165. break;
  166. }
  167. return$constellation;
  168. }
  169. js格式的:
  170. 根據(jù)生日的月份和日期,計算星座的js小函數(shù)(最簡)
  171. //根據(jù)生日的月份和日期,計算星座。http://blog.111cn.net/cuixiping/
  172. functiongetAstro(month,day){
  173. vars=”魔羯水瓶雙魚牡羊金牛雙子巨蟹獅子處女天秤天蝎射手魔羯”;
  174. vararr=[20,19,21,21,21,22,23,23,23,23,22,22];
  175. returns.substr(month*2-(day<arr[month-1]?2:0),2);
  176. }
  177. //取星座,參數(shù)分別是月份和日期
  178. functiongetxingzuo(month,day){
  179. //byGo_Rush(阿舜)fromhttp://ashun.cnblogs.com/
  180. vard=newDate(1999,month-1,day,0,0,0);
  181. vararr=[];
  182. arr.push(["魔羯座",newDate(1999,0,1,0,0,0)])
  183. arr.push(["水瓶座",newDate(1999,0,20,0,0,0)])
  184. arr.push(["雙魚座",newDate(1999,1,19,0,0,0)])
  185. arr.push(["牡羊座",newDate(1999,2,21,0,0,0)])
  186. arr.push(["金牛座",newDate(1999,3,21,0,0,0)])
  187. arr.push(["雙子座",newDate(1999,4,21,0,0,0)])
  188. arr.push(["巨蟹座",newDate(1999,5,22,0,0,0)])
  189. arr.push(["獅子座",newDate(1999,6,23,0,0,0)])
  190. arr.push(["處女座",newDate(1999,7,23,0,0,0)])
  191. arr.push(["天秤座",newDate(1999,8,23,0,0,0)])
  192. arr.push(["天蝎座",newDate(1999,9,23,0,0,0)])
  193. arr.push(["射手座",newDate(1999,10,22,0,0,0)])
  194. arr.push(["魔羯座",newDate(1999,11,22,0,0,0)])
  195. for(vari=arr.length-1;i>=0;i–){
  196. if(d>=arr[i][1])returnarr[i][0];
  197. }
  198. }
  199. functiongetxingzuo(month,day){
  200. vars=”魔羯水瓶雙魚牡羊金牛雙子巨蟹獅子處女天秤天蝎射手魔羯”;
  201. vararr=[19,50,84,116,148,181,214,246,278,310,341,373,383];
  202. for(vari=0;i<arr.length;i++){
  203. if((((month-1)<<5)+day)<=arr[i])returns.substr(i*2,2);
  204. }
  205. return“error”;
  206. }
  207. 計算生肖的:
  208. functionbirthday2BornTag($birthday){
  209. $year=substr($birthday,0,4);
  210. $bornTagarray=array(“猴”,“雞”,“狗”,“豬”,“鼠”,“牛”,“虎”,“兔”,“龍”,“蛇”,
  211. “馬”,“羊”);
  212. $index=$year%12;
  213. $bornTag=$bornTagarray[$index];
  214. return$bornTag;
  215. }
  216. echobirthday2BornTag(’1983-12-19′);

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 中西区| 峨边| 东乡县| 九龙坡区| 桐城市| 高邮市| 台南县| 沧州市| 疏勒县| 乌兰浩特市| 南木林县| 阆中市| 英吉沙县| 泰兴市| 托里县| 家居| 宣威市| 大新县| 鹰潭市| 武威市| 合水县| 榆社县| 宾川县| 泌阳县| 印江| 肥乡县| 临泉县| 来宾市| 女性| 托里县| 开远市| 庆城县| 惠来县| 崇阳县| 烟台市| 吉木萨尔县| 唐海县| 九江县| 贡觉县| 杂多县| 陇川县|