Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

I found a facebook like date system and have a little thing i wanna have fixed.

Hi everyone, So i found a facebook like time system for a cms i'm making, so when ever i upload a post it says 'Posted 5 seconds ago' after some time '5 minutes and 3 seconds' and etc. But the thing is i'm from Denmark, and we have a little bit different looking time system. and i don't really know how to add a extra $retval i made cause it just looks weird when i do it.

The code:

<?php

error_reporting(0);

// DISPLAYS COMMENT POST TIME AS "1 year, 1 week ago" or "5 minutes, 7 seconds ago", etc... function time_ago($date,$granularity=2) { $date = strtotime($date); $difference = time() - $date; $periods = array('decade' => 315360000, 'år' => 31536000, 'måned' => 2628000, 'uge' => 604800, 'dag' => 86400, 'tim' => 3600, 'minut' => 60, 'sekund' => 1); foreach ($periods as $key => $value) { if ($difference >= $value) { $time = floor($difference/$value); $difference %= $value; $retval .= ($retval ? ' og ' : '').$time.' '; $retval .= (($time > 1) ? $key.'er' : $key); $granularity--; } if ($granularity == '0') { break; } } return ' Lagt op for '.$retval.' siden.'; }

?>

1 Answer

i tried to make a extra $retval as i said that looks like this:

<?php

$retval .= (($time < 1) ? $key.'e' : $key); // Because i only want's to show e when it's under more days but it just looks weird. really weird..

?>