如果你想让输出“语法正确”,请尝试以下代码。例如,它会将“1 分钟”打印为“1 分钟”,而不是“1 分钟”,天和小时也是如此。
将以下代码放在页面代码的头部
<?php
function uptime() {
if (!$times = posix_times() ) {
return ("unknown");
} else {
$now = $times['ticks'];
$days = intval($now / (60*60*24*100));
$remainder = $now % (60*60*24*100);
$hours = intval($remainder / (60*60*100));
$remainder = $remainder % (60*60*100);
$minutes = intval($remainder / (60*100));
if ($days == 1) {$writeDays = "day";} else {$writeDays = "days";}
if ($hours == 1) {$writeHours = "hour"; } else {$writeHours = "hours";}
if ($minutes == 1) {$writeMins = "minute";} else {$writeMins = "minutes";}
return ("$days $writeDays, $hours $writeHours, $minutes $writeMins");
}
}
?>
然后将这段代码放在你想显示信息的地方
<?php
print uptime();
?>
此致,
nry