function birthday($mydate,$symbol='-'){
//计算年龄
$birth=$mydate;
list($by,$bm,$bd)=explode($symbol,$birth);
$cm=date('n');
$cd=date('j');
$age=date('Y')-$by-1;
if ($cm>$bm || $cm==$bm && $cd>$bd) $age++;
$array['age'] = $age;
//计算生肖
$animals = array(
'鼠', '牛', '虎', '兔', '龙', '蛇',
'马', '羊', '猴', '鸡', '狗', '猪'
);
$key = ($by - 1900) % 12;
$array['animals'] = $animals[$key];
//计算星座
$month = $bm;
$day = $bd;
$signs = array(
array('20'=>'水瓶座'), array('19'=>'双鱼座'),
array('21'=>'白羊座'), array('20'=>'金牛座'),
array('21'=>'双子座'), array('22'=>'巨蟹座'),
array('23'=>'狮子座'), array('23'=>'处女座'),
array('23'=>'天秤座'), array('24'=>'天蝎座'),
array('22'=>'射手座'), array('22'=>'摩羯座')
);
$key = (int)$month - 1;
list($startSign, $signName) = each($signs[$key]);
if( $day < $startSign ){
$key = $month - 2 < 0 ? $month = 11 : $month -= 2;
list($startSign, $signName) = each($signs[$key]);
}
$array['constellation'] = $signName;
return $array;
}
注意:根据某些方式,有如下方式,获取到的星座,在 1-22日获取到的星座错误
$constellation_name = array(
'水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座',
'狮子座','处女座','天秤座','天蝎座','射手座','摩羯座');
if ($day<= 22){
if ('1' != $month) $constellation = $constellation_name[$bm-2]; else $constellation = $constellation_name[11];
}else $constellation = $constellation_name[$month-1];
$array['constellation'] = $constellation;
|