Reputation: 53
I wonder if anyone could assist with this as I am not sure where to look.
I have an old site that runs on a shared server that I have little control over. I have a script that runs well on my other sites and want to add it to this older site however it doesn't display the time correctly. All my other sites run on PHP 5+ however this is the first php script on the old site which I have now discovered is running PHP 4.4.8.
So I have narrowed down the problem to a function within a larger script and think this is where the incompatibility lies. The code basically takes the data supplied and converts it into days, hours, minutes & seconds.
function time_left ($e_time) {
$e_time = strtotime($e_time);
$e_time = substr($e_time, 0, 10);
$time_stamp = explode("-", date('n-d-Y-H-i-s', $e_time));
$e_time = mktime($time_stamp[3], $time_stamp[4], $time_stamp[5], $time_stamp[0], $time_stamp[1], $time_stamp[2]);
$server_time = time();
$diff_time = ($e_time - $server_time);
if ($diff_time < 0) $diff_time = 0;
unset($time_stamp);
# get days remaining
$time_stamp[1] = floor($diff_time/60/60/24);
if($time_stamp[1] <= 0){$time_stamp[1] = "";} else {$time_stamp[1] .= "d ";}
# get hours remaining
$time_stamp[3] = floor(($diff_time - $time_stamp[1]*60*60*24)/60/60);
if($time_stamp[3] <= 0){$time_stamp[3] = "";} else {$time_stamp[3] .= "h ";}
# get minutes remaining
$time_stamp[4] = floor(($diff_time - $time_stamp[1]*60*60*24 - $time_stamp[3]*60*60)/60);
if($time_stamp[4] <= 0){$time_stamp[4] = "";} else {$time_stamp[4] .= "m ";}
return $time_stamp[1] . $time_stamp[3] . $time_stamp[4];
}
Can anyone spot anything in the above code that you think may be incompatible in PHP 4.4?
Currently if I echo the raw time data variable it shows it in raw form but when it is put through the function above it displays nothing. As I say I don't have any issues with this coding on servers operating PHP 5+
Many thanks in advance for any help!
* Added
Ok I think I have isolated what the issue is and that is strtotime
The raw input that strtotime gets is this: 2013-03-18T21:38:58.000Z
At the moment because the script is running under PHP 4.4 if I echo this bit:
$e_time = strtotime($e_time);
It always returns a value of -124 but I am not sure why??
Upvotes: 0
Views: 98
Reputation: 1247
Remove
unset($time_stamp);
this line.
Not sure why you're unsetting it when you want to do operations on it right afterwards. Hope that helps
Upvotes: 2