//根据生日计算年龄
function birToAge($birthday){
if(!empty($birthday)){
$age = null;
$year = date('Y',strtotime($birthday));
$month = date('m',strtotime($birthday));
$now_year = date('Y');
$now_month = date('m');
$yearDiff = $now_year-$year;
$monthDiff = $now_month-$month;
if($yearDiff==0){
if($monthDiff==0){
$age = "未满月";
}else{
$age = $monthDiff."个月";
}
}else if($yearDiff<0){
$age = "生日格式不对";
}else{
if($monthDiff==0){
$age = $yearDiff."岁";
}else if($monthDiff<0){
$ageYer = $yearDiff-1;
if($ageYer==0){
$age = 12-$month+$now_month."月";
}else{
$age = ($yearDiff-1)."岁".(12-$month+$now_month)."月";
}
}else{
$age = $yearDiff."岁".$monthDiff."月";
}
}
return $age;
}
}