0
I’m having trouble 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>
A simple solution would be to just remove the "s" from the $periods[$val] .= "s";
, only it would be something half mouth as "5 months ago", the right is to leave "5 months ago".
Managed to solve one, but another kkkk https://i.imgur.com/5SSVWZx.png appears
– Vitor Hugo
I’m almost giving up, I’ve searched all over google and I can’t find any solution.
– Vitor Hugo
edited the answer see if solved
– Costamilam
just forehead, it worked perfectly. thank you very much, I spent all day cracking head with it :)
– Vitor Hugo