【发布时间】:2011-09-07 14:51:36
【问题描述】:
我已经创建了一段代码,并且我已经在我的 PHP 代码中“请求一次”了很长一段时间了。它在我的本地 PC 上运行良好,但是当我将它上传到我的服务器时,它会出现以下错误:
Parse error: syntax error, unexpected T_ELSE in /home/makequiz/public_html/nitpicker/func.php on line 47
函数如下:
function howLongAgo($unix_time) {
// This function shows the unix time stamp
// as number of seconds, minutes, hours, days, months, years ago
// Get the time difference between time specified and the current unix time
$time_difference = time () - $unix_time;
$seconds_ago = $time_difference;
$minutes_ago = $time_difference / 60;
$hours_ago = $time_difference / 3600;
$days_ago = $time_difference / 86400;
$months_ago = $time_difference / 2629743;
$years_ago = $time_difference / 31556926;
if ($time_difference < 60) {
// Seconds Ago
return round ( $time_difference ) . ' Seconds Ago';
} else if ( ($time_difference >= 60) && ($time_difference < 3600) ) {
// Minutes Ago
if (round ( $time_difference / 60 ) == 1) {
return round ( $time_difference / 60 ) . " Minute Ago";
} else {
return round ( $time_difference / 60 ) . " Minutes Ago";
}
} else if ($time_difference >= 3600 && $time_difference < 86400) {
// Hours Ago
if (round ( $time_difference / 3600 ) == 1) {
return round ( $time_difference / 3600 ) . " Hour Ago";
} else {
return round ( $time_difference / 3600 ) . " Hours Ago";
}
} else if ($time_difference >= 86400 && $time_difference < 2629743) {
// Days Ago
if (round ( $time_difference / 86400 ) == 1) {
return round ( $time_difference / 86400 ) . " Day Ago";
} else {
return round ( $time_difference / 86400 ) . " Days Ago";
}
} else if ($time_difference >= 2629743 && $time_difference < 31556926) {
// Months Ago
if (round ( $time_difference / 2629743 ) == 1) {
return round ( $time_difference / 2629743 ) . " Month Ago";
} else {
return round ( $time_difference / 2629743 ) . " Months Ago";
}
} else if ($time_difference >= 31556926) {
// Years Ago
if (round ( $time_difference / 31556926 ) == 1) {
return round ( $time_difference / 31556926 ) . " Year Ago";
} else {
return round ( $time_difference / 31556926 ) . " Years Ago";
}
}
}
这个错误即将出现,即使我的代码中根本没有调用该函数。
任何人都可以看到代码中的任何错误,因为我看不到:(
【问题讨论】:
-
请指出第47行
-
您提供的来源是正确的。问题似乎出在其他地方。
-
“即使我根本没有调用该函数”。没关系,解析就是解析,即使它没有被调用(这首先不是一件好事,为什么还要它呢?)
-
您发布的代码在语法上是正确的:codepad.org/YbYI0Rp4
标签: php function if-statement