format('n'); $day = $birthdate->format('j'); $westernZodiac = ''; if (($month == 3 && $day >= 21) || ($month == 4 && $day <= 19)) { $westernZodiac = '白羊座'; } elseif (($month == 4 && $day >= 20) || ($month == 5 && $day <= 20)) { $westernZodiac = '金牛座'; } elseif (($month == 5 && $day >= 21) || ($month == 6 && $day <= 20)) { $westernZodiac = '双子座'; } elseif (($month == 6 && $day >= 21) || ($month == 7 && $day <= 22)) { $westernZodiac = '巨蟹座'; } elseif (($month == 7 && $day >= 23) || ($month == 8 && $day <= 22)) { $westernZodiac = '狮子座'; } elseif (($month == 8 && $day >= 23) || ($month == 9 && $day <= 22)) { $westernZodiac = '处女座'; } elseif (($month == 9 && $day >= 23) || ($month == 10 && $day <= 22)) { $westernZodiac = '天秤座'; } elseif (($month == 10 && $day >= 23) || ($month == 11 && $day <= 21)) { $westernZodiac = '天蝎座'; } elseif (($month == 11 && $day >= 22) || ($month == 12 && $day <= 21)) { $westernZodiac = '射手座'; } elseif (($month == 12 && $day >= 22) || ($month == 1 && $day <= 19)) { $westernZodiac = '摩羯座'; } elseif (($month == 1 && $day >= 20) || ($month == 2 && $day <= 18)) { $westernZodiac = '水瓶座'; } else { $westernZodiac = '双鱼座'; } // 计算中国生肖 $year = $birthdate->format('Y'); $chineseZodiac = ''; $zodiacAnimals = ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪']; $chineseZodiac = $zodiacAnimals[($year - 1900) % 12]; echo json_encode([ 'westernZodiac' => $westernZodiac, 'chineseZodiac' => $chineseZodiac ]); } else { echo json_encode(['error' => '无效的请求']); }