php选择星座,PHP日期得到星座

/**

* 星座判断

*/

function getConstellation($birthday, $format = null) {

@header ( Content-type: text/html;charset=UTF-8 );

$pattern = /^\\d{4}-\\d{1,2}-\\d{1,2}$/;

if (! preg_match ( $pattern, $birthday, $matchs )) {

return null;

}

$date = explode ( -, $birthday );

$year = $date [0];

$month = $date [1];

$day = $date [2];

if ($month < 1 || $month > 12 || $day < 1 || $day > 31) {

return null;

}

//设定星座数组

$constellations = array (10-摩羯座, 11-水瓶座, 12-双鱼座, 1-白羊座, 2-金牛座, 3-双子座, 4-巨蟹座, 5-狮子座, 6-处女座, 7-天秤座, 8-天蝎座, 9-射手座 );

//设定星座结束日期的数组,用于判断

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

//如果参数format被设置,则返回值采用format提供的数组,否则使用默认的数组

if ($format != null) {

$values = $format;

} else {

$values = $constellations;

}

//根据月份和日期判断星座

switch ($month) {

case 1 :

if ($day <= $enddays [0]) {

$constellation = $values [0];

} else {

$constellation = $values [1];

}

break;

case 2 :

if ($day <= $enddays [1]) {

$constellation = $values [1];

} else {

$constellation = $values [2];

}

break;

case 3 :

if ($day <= $enddays [2]) {

$constellation = $values [2];

} else {

$constellation = $values [3];

}

break;

case 4 :

if ($day <= $enddays [3]) {

$constellation = $values [3];

} else {

$constellation = $values [4];

}

break;

case 5 :

if ($day <= $enddays [4]) {

$constellation = $values [4];

} else {

$constellation = $values [5];

}

break;

case 6 :

if ($day <= $enddays [5]) {

$constellation = $values [5];

} else {

$constellation = $values [6];

}

break;

case 7 :

if ($day <= $enddays [6]) {

$constellation = $values [6];

} else {

$constellation = $values [7];

}

break;

case 8 :

if ($day <= $enddays [7]) {

$constellation = $values [7];

} else {

$constellation = $values [8];

}

break;

case 9 :

if ($day <= $enddays [8]) {

$constellation = $values [8];

} else {

$constellation = $values [9];

}

break;

case 10 :

if ($day <= $enddays [9]) {

$constellation = $values [9];

} else {

$constellation = $values [10];

}

break;

case 11 :

if ($day <= $enddays [10]) {

$constellation = $values [10];

} else {

$constellation = $values [11];

}

break;

case 12 :

if ($day <= $enddays [11]) {

$constellation = $values [11];

} else {

$constellation = $values [0];

}

break;

}

return $constellation;

}

echo getConstellation ( 1990-07-01 );

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值