PHP輸出星座,php 通過日期推算星座的方法

2021-10-25 20:34:04 字數 3753 閱讀 4649

php可以通過出生年月日來推算出自己是什麼星座的,網上搜尋了一些好用的**段列出出來,大家可以參考一下。

星座與時間對應表魔羯座(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:php輸入月份與日來計算星座的方法function get_constellation($birth_month,$birth_date)elseelseelse if(($month == 2 && $day >= 19) || ($month == 3 && $day <= 20)) else if (($month == 3 && $day >= 21) || ($month == 4 && $day <= 19)) else if (($month == 4 && $day >= 20) || ($month == 5 && $day <= 20)) else if (($month == 5 && $day >= 21) || ($month == 6 && $day <= 21)) else if (($month == 6 && $day >= 22) || ($month == 7 && $day <= 22)) else if (($month == 7 && $day >= 23) || ($month == 8 && $day <= 22)) else if (($month == 8 && $day >= 23) || ($month == 9 && $day <= 22)) else if (($month == 9 && $day >= 23) || ($month == 10 && $day <= 23)) else if (($month == 10 && $day >= 24) || ($month == 11 && $day <= 22)) else if (($month == 11 && $day >= 23) || ($month == 12 && $day <= 21)) else if (($month == 12 && $day >= 22) || ($month == 1 && $day <= 19)) {

$xingzuo = "摩羯座";

return $xingzuo;

echo get_xingzuo(8,11);

echo get_xingzuo(9,11);

示例3:php獲取星座的方法,需要輸入月份與日期function getconstellation($month, $day){

if(($month  12) || ($day  31)) return false;

$constellations = [

['20' => '水瓶座'], ['19' => '雙魚座'], ['21' => '白羊座'], ['20' => '金牛座'],

['21' => '雙子座'], ['22' => '巨蟹座'], ['23' => '獅子座'], ['23' => '**座'],

['23' => '天秤座'], ['24' => '天蠍座'], ['22' => '射手座'], ['22' => '魔羯座']

list($constellation_key, $constellation_value) = each($constellations[(int)$month - 1]);

if($day 

list($constellation_key, $constellation_value) =

each($constellations[($month - 2 

return $constellation_value;

echo getconstellation(8,11);

echo getconstellation(9,11);

示例4:php 通過格式化的日期輸出星座// 輸入格式化後的日期,(年-月-日)

function getconstellation($birthday){

$date = explode('-', $birthday);

$month = $date[1];

$day = $date[2];

//英文星座陣列

// $values = array('capricorn','aquarius','pisces','aries','taurus','gemini','cancer','leo','virgo','libra','scorpio','sagittarius');

//漢字星座陣列

$values = array('摩羯座','水瓶座','雙魚座','白羊座','金牛座','雙子座','巨蟹座','獅子座','**座','天秤座','天蠍座','射手座');

//設定星座結束日期的陣列,用於判斷

$enddays = array(19, 18, 20, 20, 20, 21, 22, 22, 22, 22, 21, 21,);

switch ($month){

case 1:

return $day <= $enddays[0] ? $values[0] : $values[1];

break;

case 2:

return $day <= $enddays[1] ? $values[1] : $values[2];

break;

case 3:

return $day <= $enddays[2] ? $values[2] : $values[3];

break;

case 4:

return $day <= $enddays[3] ? $values[3] : $values[4];

break;

case 5:

return $day <= $enddays[4] ? $values[4] : $values[5];

break;

case 6:

return $day <= $enddays[5] ? $values[5] : $values[6];

break;

case 7:

return $day <= $enddays[6] ? $values[6] : $values[7];

break;

case 8:

return $day <= $enddays[7] ? $values[7] : $values[8];

break;

case 9:

return $day <= $enddays[8] ? $values[8] : $values[9];

break;

case 10:

return $day <= $enddays[9] ? $values[9] : $values[10];

break;

case 11:

return $day <= $enddays[10] ? $values[10] : $values[11];

break;

case 12:

return $day <= $enddays[11] ? $values[11] : $values[0];

break;

return '';

echo getconstellation('1980-08-11');

echo getconstellation('1980-09-11');

php 求日期,PHP 日期轉換

php 抓昨天日期的 date d m y time 24 3600 其它一些日期 code 的應用.mysql日期和時間函式不求人 所有 mysql 日期函式 應該全都用到了吧.xd php 入門必讀 日期及時間 echo date y m d h i s n timestamp mktime d...

php中如何輸出時間 PHP的日期和時間

標籤 unix時間戳 從 unix 紀元 格林威治時間 1970 年 1 月1日 00 00 00 到當前時間的秒數 time 函式返回乙個當前系統的時間戳 mktime 取得乙個日期的 unix 時間戳 1 格式 int mktime 時 分 秒 月 日 年 is dst區 2 注意 is dst...

通過table標籤,PHP輸出EXCEL的實現方法

關鍵 複製 如下 php header c程式設計客棧ontent type application vnd.ms excel header conten disposition filename hp.xlsx 第一句是用來宣告檔案內容的格式 第二局是用來修改檔名的。如果沒有第二個語句的話,生成的...