Jump to content

Recommended Posts

Hello, I have this script that converts my unixtimestamp into "XXXX Ago" time format.

 

 

function timeAgo($tm,$rcs = 0) {
    $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 .= timeAgo($_tm, --$rcs);
    return $x;
}

 

 

This is how I use the script on my forum script/site.

timeAgo($member['last_activity'])

$member['last_activity'] is a unix Timestamp.

 

This works wonderful! but here's the problem! I am trying to make it go 2 levels more.  Like instead of just "2 Minutes ago"  It says:

2 Minutes 20 seconds ago

 

So then I apply how to do that:

 

timeAgo($member['last_activity'],2)

 

See the number 2? Then all of sudden I get this weird ass error...

 

Fatal error: Call to undefined function timeAgo() in myscript.php on line 1187

 

1187 line is:

if(($rcs > 0)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= timeAgo($_tm, --$rcs);

 

 

Why would it say undefined function when it's in it's own function?

This is weird as hell I am absolutely stumped, any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/252831-weirdest-error-ive-ever-seen/
Share on other sites

Your function works for me.

 

I know it works, but it brings the error when I try

 

timeAgo($member['last_activity'],2);

 

Whenever I try to add the ,1 or ,2 or ,3 to show "2minutes xx seconds ago" or whatever, instead of just the "2 minutes ago"

 

Try that way, and let me know ty

Works for me, even with constants up to 5 as the second argument.

 

Copy and paste your code from HERE back into your actual code and try it again.  Maybe you're namespaced weird or there's some non-english character somehow.  Copying and pasting works for me.

 

-Dan

Also, this is pretty slick.

 

Wow, the problem was:

 

I had to add:

 

$this->timeAgo($_tm, --$rcs);

 

Because I guess I was calling it from a different .php file, this is in functions.php, and where I am calling it is in skin_profile.php.

 

I feel like a fool and sorry for wasting everyones time, lol I guess it just helps me to explain my code more out and I can understand it more? Thanks all for trying.

 

I am going to mark this Resolved.

 

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.