Monkuar Posted December 9, 2011 Share Posted December 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252831-weirdest-error-ive-ever-seen/ Share on other sites More sharing options...
scootstah Posted December 9, 2011 Share Posted December 9, 2011 Your function works for me. Quote Link to comment https://forums.phpfreaks.com/topic/252831-weirdest-error-ive-ever-seen/#findComment-1296233 Share on other sites More sharing options...
Monkuar Posted December 9, 2011 Author Share Posted December 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/252831-weirdest-error-ive-ever-seen/#findComment-1296237 Share on other sites More sharing options...
ManiacDan Posted December 9, 2011 Share Posted December 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/252831-weirdest-error-ive-ever-seen/#findComment-1296240 Share on other sites More sharing options...
ManiacDan Posted December 9, 2011 Share Posted December 9, 2011 Also, this is pretty slick. Quote Link to comment https://forums.phpfreaks.com/topic/252831-weirdest-error-ive-ever-seen/#findComment-1296243 Share on other sites More sharing options...
Monkuar Posted December 9, 2011 Author Share Posted December 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252831-weirdest-error-ive-ever-seen/#findComment-1296248 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.