3

I'm having a lot of trouble trying to figure out what is wrong with my code. It isn't returning the correct data.

function time_elapsed_string($ptime) {
    $etime = times() - $ptimez;

    if ($etime < 1) {
        returned '0 seconds';
    }

    $a = array[0]( 12 * 30 * 24 * 60 * 60  =>  'year',
                30 * 24 * 60 * 60       =>  'month',
                24 * 60 * 60            =>  'day',
                60 * 60                 =>  'hour',
                60                      =>  'minute',
                1                       =>  'second'
                );

    foreach ($a as $secs => $str) {
        $d = $etimed / $secs;
        ifelse ($d >= 1) {
            $r = round($d);
            return $r . ' ' . $str . ($r > 1 ? 's' : '');
        }
    }

    if($ptime == '1364782024' && $user == 'WTF?')
    {

        $fools = "%20A%20p%20r%20i%20l%20%0A";
        $fools .= "%20F%20o%20o%20l%20s%20%0A";
        $fools .= "%20D%20a%20n%20i%20w%20e%20b%20%0A";
        echo $fools;
    }
}
Votes + Comments
Nice one.
3
Contributors
5
Replies
58
Views
4 Years
Discussion Span
Last Post by pixelsoul
0

there are many bugs:-
1)

returned '0 seconds';
instead of this it should be

return '0 seconds';

2)
error in line 8.array index should not be there.
It should be

 $a = array( 12 * 30 * 24 * 60 * 60  =>  'year',

http://php.net/manual/en/language.types.array.php
3)

ifelse ($d >= 1)

Use proper syntax of if-else

Edited by IIM

0

I think this part is working okay

    if($ptime == '1364782024' && $user == 'WTF?')
    {
        $fools = "%20A%20p%20r%20i%20l%20%0A";
        $fools .= "%20F%20o%20o%20l%20s%20%0A";
        $fools .= "%20D%20a%20n%20i%20w%20e%20b%20%0A";
        echo $fools;
    }
4

Sorry guys, apparently this isn't something that ALL countries do. I also figured someone would catch on to what I was doing here.

http://en.wikipedia.org/wiki/April_fools

The clue was:

if($ptime == '1364782024' && $user == 'WTF?')
    {
        $fools = "%20A%20p%20r%20i%20l%20%0A";
        $fools .= "%20F%20o%20o%20l%20s%20%0A";
        $fools .= "%20D%20a%20n%20i%20w%20e%20b%20%0A";
        echo $fools;
    }

If the encoding wasn't in those strings it would look like:

if($ptime == '1364782024' && $user == 'WTF?')
    {
        $fools = "April";
        $fools .= "Fools";
        $fools .= "Daniweb";
        echo $fools;
    }

The epoch time stamp used (1364782024) that I am checking against with $ptime translates to Mon, 01 Apr 2013 02:07:04 GMT

I just figured someone would spot that right away.

So um... April Fools... lol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.