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
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.