Created
April 28, 2012 08:05
-
-
Save YuheiNakasaka/2517018 to your computer and use it in GitHub Desktop.
how to get age from birthday in facebook's PHPSDK.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ユーザーの生年月日から年齢の取得 | |
//アクセストークンの取得などは割愛 | |
$birthday = $me -> birthday; | |
$birth = explode('/',$birthday); | |
$year = date("Y");$month = date("n");$day = date("j");//今日の日付 | |
$b_month = $birth[0]; | |
$b_day = $birth[1]; | |
$age = $year - intval($birth[2]); | |
//月、日に桁埋めの0が含まれていたら取り除く | |
if(strstr($birth[0],'0',true) == ''){ | |
$b_month = intval(ltrim($birth[0],'0')); | |
} | |
if(strstr($birth[1],'0',true) == ''){ | |
$b_day = intval(ltrim($birth[1],'0')); | |
} | |
//年齢の計算 | |
if($b_month > $month){ | |
$age = $age - 1; | |
}elseif($b_month === $month){ | |
if($b_day > $day){ | |
$age = $age - 1; | |
} | |
}else{ | |
$age; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment