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

首頁 > 語言 > PHP > 正文

php中根據生日判斷星座、生肖程序代碼

2024-09-04 11:45:26
字體:
來源:轉載
供稿:網友

星座判斷很簡單我們要統計出每個星期所有日期時間段了,然后獲取日期進行查詢即可了,下面我給大家舉兩個實例,有需要的同學可參考.

星座:我是根據這個時間表寫的,該時間表未必準確.

'水瓶座'=>'(1/22-2/21)',    '雙魚座'=>'(2/22-3/21)',
'白羊座'=>'(3/22-4/21)',    '金牛座'=>'(4/22-5/21)',
'雙子座'=>'(5/22-6/21)',    '巨蟹座'=>'(6/22-7/21)',
'獅子座'=>'(7/22-8/21)',    '處女座'=>'(8/22-9/21)',
'天秤座'=>'(9/22-10/21)',   '天蝎座'=>'(10/22-11/21)',
'射手座'=>'(11/22-12/21)',   '摩羯座'=>'(12/22-1/21)'

根據日期判斷星座函數

實例代碼如下:

  1. function yige_constellation($month$day) { 
  2.  // 檢查參數有效性  
  3.  if ($month < 1 || $month > 12 || $day < 1 || $day > 31) return false; 
  4.  
  5.  // 星座名稱以及開始日期 
  6.  $constellations = array
  7.   array"20" => "寶瓶座"), 
  8.   array"19" => "雙魚座"), 
  9.   array"21" => "白羊座"), 
  10.   array"20" => "金牛座"), 
  11.   array"21" => "雙子座"), 
  12.   array"22" => "巨蟹座"), 
  13.   array"23" => "獅子座"), 
  14.   array"23" => "處女座"), 
  15.   array"23" => "天秤座"), 
  16.   array"24" => "天蝎座"), 
  17.   array"22" => "射手座"), 
  18.   array"22" => "摩羯座"
  19.  ); 
  20.  
  21.  list($constellation_start$constellation_name) = each($constellations[(int)$month-1]); 
  22.  
  23.  if ($day < $constellation_start) list($constellation_start$constellation_name) = each($constellations[($month -2 < 0) ? $month = 11: $month -= 2]); 
  24.  
  25.  return $constellation_name

下面這個更全面可直接根據生日檢查年齡,生肖,星座

實例代碼如下:

  1. <?php 
  2. /** 
  3. * 根據生日中的月份和日期來計算所屬星座 
  4. * 
  5. * @param int $birth_month 
  6. * @param int $birth_date 
  7. * @return string 
  8. */ 
  9. function get_constellation($birth_month,$birth_date
  10. //判斷的時候,為避免出現1和true的疑惑,或是判斷語句始終為真的問題,這里統一處理成字符串形式 
  11. $birth_month = strval($birth_month); 
  12.  
  13. $constellation_name = array
  14.       '水瓶座','雙魚座','白羊座','金牛座','雙子座','巨蟹座'
  15.       '獅子座','處女座','天秤座','天蝎座)','射手座','摩羯座' 
  16.       ); 
  17.  
  18. if ($birth_date <= 22) 
  19.   if ('1' !== $birth_month
  20.   { 
  21.    $constellation = $constellation_name[$birth_month-2]; 
  22.   } 
  23.   else 
  24.   { 
  25.    $constellation = $constellation_name[11]; 
  26.   } 
  27. else 
  28.   $constellation = $constellation_name[$birth_month-1]; 
  29.  
  30. return $constellation
  31.  
  32. /** 
  33. * 根據生日中的年份來計算所屬生肖 
  34. * 
  35. * @param int $birth_year 
  36. * @return string 
  37. */ 
  38. function get_animal($birth_year
  39. //1900年是子鼠年 
  40. $animal = array
  41.     '子鼠','丑牛','寅虎','卯兔','辰龍','巳蛇'
  42.     '午馬','未羊','申猴','酉雞','戌狗','亥豬' 
  43.     ); 
  44.  
  45. $my_animal = ($birth_year-1900)%12; 
  46. return $animal[$my_animal]; 
  47.  
  48. /** 
  49. * 根據生日來計算年齡 
  50. * 
  51. * 用Unix時間戳計算是最準確的,但不太好處理1970年之前出生的情況 
  52. * 而且還要考慮閏年的問題,所以就暫時放棄這種方式的開發,保留思想 
  53. * 
  54. * @param int $birth_year 
  55. * @param int $birth_month 
  56. * @param int $birth_date 
  57. * @return int 
  58. */ 
  59. function get_age($birth_year,$birth_month,$birth_date
  60. $now_age = 1; //實際年齡,以出生時為1歲計 
  61. $full_age = 0; //周歲,該變量放著,根據具體情況可以隨時修改 
  62.  
  63. $now_year   = date('Y',time()); 
  64. $now_date_num  = date('z',time()); //該年份中的第幾天 
  65. $birth_date_num = date('z',mktime(0,0,0,$birth_month,$birth_date,$birth_year)); 
  66.  
  67. $difference = $now_date_num - $birth_date_num
  68. if ($difference > 0) 
  69.   $full_age = $now_year - $birth_year
  70. else 
  71.   $full_age = $now_year - $birth_year - 1; 
  72.  
  73. $now_age = $full_age + 1; 
  74.  
  75. return $now_age
  76.  
  77. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 白朗县| 青州市| 永修县| 泰州市| 广汉市| 阿图什市| 湘阴县| 乌兰察布市| 柏乡县| 旌德县| 灵寿县| 龙海市| 灌南县| 朝阳县| 璧山县| 靖安县| 那坡县| 新田县| 襄樊市| 满洲里市| 文成县| 清河县| 台州市| 班戈县| 邛崃市| 青浦区| 九龙坡区| 临安市| 铁力市| 彭州市| 大荔县| 高碑店市| 长顺县| 中卫市| 开封市| 曲水县| 潮州市| 涞水县| 穆棱市| 望谟县| 高平市|