Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function timeElapsed($t) {
- $t = time() - $t;
- $tokens = array (
- 31536000 => array('ann', 'o', 'i'),
- 2592000 => array('mes', 'e', 'i'),
- 604800 => array('settiman', 'a', 'e'),
- 86400 => array('giorn', 'o', 'i'),
- 3600 => array('or', 'a', 'e'),
- 60 => array('minut', 'o', 'i'),
- 1 => array('second', 'o', 'i')
- );
- foreach ($tokens as $unit => $text) {
- if ($t < $unit) continue;
- $numberOfUnits = floor($t / $unit);
- $suffix = $text[1];
- if($numberOfUnits > 1)
- $suffix = $text[2];
- return $numberOfUnits . ' ' . $text[0] . $suffix;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment