我有一段時間在PHP函數,我用它來返回,如果用戶在線或用戶最後一次看到。如何解決Timeago錯誤
function tj_online_last($ptime) {
$estimate_time = time() - strtotime($ptime);
// if time diff is less than 1 minute then user is online
if ($estimate_time < 60) {
return 'online';
}
$condition = array(
12 * 30 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second',
);
foreach($condition as $secs => $str) {
$d = $estimate_time/$secs;
if ($d >= 1) {
$r = round($d);
return $r.' '.$str.($r > 1 ? 's' : '').' ago';
}
}
}
現在這裏的問題在這裏,當用戶第一次沒有登錄到他的帳戶的時間值是'NULL'。我想回到'永遠',而不是'48年前'令人討厭的,因爲我無法處理錯誤。
然後'回「從來沒有」;',什麼是問題? –