I'm having problem in determining the plural in the time display.
Function:
/**
* @ http://us.php.net/manual/en/function.time.php#71342
*/
function time_ago($timestamp, $recursive = 0)
{
$current_time = time();
$difference = $current_time - $timestamp;
$periods = array("segundo", "minuto", "hora", "dia", "semana", "mês", "ano", "década");
$lengths = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
for ($val = sizeof($lengths) - 1; ($val >= 0) && (($number = $difference / $lengths[$val]) <= 1); $val--);
if ($val < 0) $val = 0;
$new_time = $current_time - ($difference % $lengths[$val]);
$number = floor($number);
if($number != 1)
{
$periods[$val] .= "s";
}
$text = sprintf("%d %s ", $number, $periods[$val]);
if (($recursive == 1) && ($val >= 1) && (($current_time - $new_time) > 0))
{
$text .= time_ago($new_time);
}
return $text;
}
<span class="time"><?=time_ago($item['mtime'])?> atrás</span>
Asimplesolutionwouldbetojustremovethe"s" from $periods[$val] .= "s";
, but it would be something half a mouth like "5 months ago", the right thing is to leave "5 months ago".