对应哪个星座





getMonth();
$lunarDay = $lunarDate->getDay();

// 计算阳历对应的星座
$zodiacSign = getZodiacSign($birthdate);

// 输出查询结果
echo ”

查询结果:

“;
echo “”;
echo “”;
echo “”;
echo ”

阳历日期 农历日期 星座
$birthdate $lunarMonth 月 $lunarDay 日 $zodiacSign

“;
}

// 计算阳历对应的星座
function getZodiacSign($birthdate) {
$month = date(‘n’, strtotime($birthdate));
$day = date(‘j’, strtotime($birthdate));

$zodiacSigns = array(
array(“from” => 3, “to” => 20, “sign” => “白羊座”),
array(“from” => 4, “to” => 20, “sign” => “金牛座”),
array(“from” => 5, “to” => 21, “sign” => “双子座”),
array(“from” => 6, “to” => 22, “sign” => “巨蟹座”),
array(“from” => 7, “to” => 22, “sign” => “狮子座”),
array(“from” => 8, “to” => 23, “sign” => “处女座”),
array(“from” => 9, “to” => 23, “sign” => “天秤座”),
array(“from” => 10, “to” => 23, “sign” => “天蝎座”),
array(“from” => 11, “to” => 22, “sign” => “射手座”),
array(“from” => 12, “to” => 21, “sign” => “摩羯座”),
array(“from” => 1, “to” => 20, “sign” => “水瓶座”),
array(“from” => 2, “to” => 19, “sign” => “双鱼座”)
);

foreach ($zodiacSigns as $zodiacSign) {
if ($month == $zodiacSign[“from”] && $day <= $zodiacSign[“to”]) {
return $zodiacSign[“sign”];
} else if ($month == $zodiacSign[“to”] && $day >= $zodiacSign[“from”]) {
return $zodiacSign[“sign”];
}
}
}

// 农历日期类
class LunarDate {
private $year;
private $month;
private $day;

public function __construct($date) {
$date = date(‘Y-m-d’, strtotime($date));
$lunarDate = new ChineseCalendar($date);
$this->year = $lunarDate->getYear();
$this->month = $lunarDate->getMonth();
$this->day = $lunarDate->getDay();
}

public function getYear() {
return $this->year;
}

public function getMonth() {
return $this->month;
}

public function getDay() {
return $this->day;
}
}
?>

By botpp

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注