Reputation: 71
i know, it should be very easy, but i have problems with the time functions in PHP. I have a string like "1 h 38 min" and i want to convert it to an integer with the numbers of minutes. Any help or is that to trivial? ;)
Upvotes: 1
Views: 276
Reputation: 134
Here is some code that is a bit more robust than sscanf and a bit more specific to using time (and works with older versions of PHP):
$input = '1 d 1 hour 38 min';
$usableInput = trim(str_replace(array(' y ', ' m ', ' d ', ' h ', ' s '), array(' years ', ' months ', ' days ', ' hours ', ' seconds '), " $input "));
$now = time();
$seconds = strtotime("+$usableInput", $now) - $now;
$minutes = floor($seconds / 60);
Upvotes: 0