Jump to content

This beautiful Script needs some help!


Monkuar

Recommended Posts

Okay, I need to make it so it shows " ago " after the time it states.

 

It shows "2minutes 20 seconds" but I can't figure out how to make it say

 

"2minutes 20 seconds ago" (simply just need to add "ago" after)

 

This uses alot of ternary operators, and I am not very knowledgable in that area, so if You can help, it would be great.

 

 

function timeAgo($tm,$rcs = 1) {
    $cur_tm = time(); $dif = $cur_tm-$tm;
    $pds = array('second','minute','hour','day','week','month','year','decade');
    $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);
    for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]);

    $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]);
    if(($rcs > 0)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= $this->timeAgo($_tm, --$rcs);
    return $x;
}

 

Simply, just need to add "ago" somewhere, but I can't figure it out, this uses unixtimestamp also.

Link to comment
https://forums.phpfreaks.com/topic/252898-this-beautiful-script-needs-some-help/
Share on other sites

  Quote

There's no output in that function.

 

You should append it to your echo statement.

 

echo $obj->timeAgo($arg) . ' ago';

 

I just did

 

   return $x .'ago';

 

wait, doesn't work it shows 2 " ago's "

 

I will try your way, and just have to manually edit each time it is called. let me see

 

Thank you so much, :) was editing bunch of stuff for ages couldn't get anything to work.

 

II am very happy.

Resolved

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.