根据生日计算年龄

function age($date){
	$year_diff = '';
	$time = strtotime($date);//将任何英文文本的日期时间描述解析为 UNIX 时间戳
	if(FALSE === $time){
		return '';
	}

	$date = date('Y-m-d', $time);
	list($year,$month,$day) = explode("-",$date);//explode 分解字符串 变为数组 list 把数组中的值赋给一些变量
	$year_diff = date("Y") – $year;
	$month_diff = date("m") – $month;
	$day_diff = date("d") – $day;
	if ($day_diff < 0 || $month_diff < 0) $year_diff–;

	return $year_diff;
}
posted @ 2014-04-04 16:07  土豆_大强  阅读(449)  评论(0)    收藏  举报