3 function humanTiming ($time)
5 $time = time() - $time; // to get the time since that moment
17 foreach ($tokens as $unit => $text) {
18 if ($time < $unit) continue;
19 $numberOfUnits = floor($time / $unit);
20 return $numberOfUnits.' '.$text.(($numberOfUnits>1)?
's':'');
24 function absHumanTiming($time)
27 $now_date = date("U", time());
28 $time = strtotime($time);
30 if($now_date < $time) {
31 $time = ($time - $now_date); // number of seconds into the future
32 $time = $now_date - $time; // subtract difference from current time
33 $out .= humanTiming($time)." left";
34 } else if ($now_date > $time) {
35 $out .= humanTiming($time)." ago";
42 function tab2space($text, $spaces = 4)
44 // Explode the text into an array of single lines
45 $lines = explode("\n", $text);
47 // Loop through each line
48 foreach ($lines as $line)
50 // Break out of the loop when there are no more tabs to replace
51 while (false !== $tab_pos = strpos($line, "\t"))
53 // Break the string apart, insert spaces then concatenate
54 $start = substr($line, 0, $tab_pos);
55 $tab = str_repeat(' ', $spaces - $tab_pos %
$spaces);
56 $end = substr($line, $tab_pos +
1);
57 $line = $start . $tab . $end;
61 return implode("\n", $result);