note 34253 added to function.posix-times
| From: | not_rich_yet at hotmail dot com | Date: | Sat, 19 Jul 2003 21:21:56 +0000 |
| Subject: | note 34253 added to function.posix-times | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52399@lists.php.net to get a copy of this message | ||
If you want the output to be 'grammatically correct' then try the following code. It will
eg print '1 minute' as opposed to '1 minutes', the same goes for days and hours:
Put the following code somewhere in the head of the page code:
<?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");
}
}
?>
Then put this bit where you want the info displayed:
<?php
print uptime();
?>
Regards,
nry
----
Manual Page -- http://www.php.net/manual/en/function.posix-times.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34253
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34253&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34253&report=yes