Advertisement
Flyfishes

Untitled

Jul 11th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. function time_elapsed_string($time)
  2. {
  3.     $time = (time() + 80) - $time;
  4.        
  5.     $tokens = array(
  6.         31536000 => 'year',
  7.         2592000 => 'month',
  8.         604800 => 'week',
  9.         86400 => 'day',
  10.         3600 => 'hour',
  11.         60 => 'minute',
  12.         1 => 'second'
  13.     );
  14.  
  15.     foreach($tokens as $unit => $text)
  16.     {
  17.         if($time < $unit) continue;
  18.         $numberOfUnits = floor($time / $unit);
  19.         return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement