Monkuar Posted December 10, 2011 Share Posted December 10, 2011 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 More sharing options...
xyph Posted December 10, 2011 Share Posted December 10, 2011 There's no output in that function. You should append it to your echo statement. echo $obj->timeAgo($arg) . ' ago'; Link to comment https://forums.phpfreaks.com/topic/252898-this-beautiful-script-needs-some-help/#findComment-1296596 Share on other sites More sharing options...
Monkuar Posted December 10, 2011 Author Share Posted December 10, 2011 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 Link to comment https://forums.phpfreaks.com/topic/252898-this-beautiful-script-needs-some-help/#findComment-1296598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.