Skip to content

Instantly share code, notes, and snippets.

@wizardfrag
Last active December 17, 2015 01:59
Show Gist options
  • Save wizardfrag/5532597 to your computer and use it in GitHub Desktop.
Save wizardfrag/5532597 to your computer and use it in GitHub Desktop.
Convert a time string to an integer.
<?php
function string2int($string = "00:00:00") {
$seconds = 0;
$string_parts = explode(':', $string);
$exponent = 0;
while (($timepart = array_pop($string_parts)) !== NULL) {
$timepart = intval($timepart);
$seconds += intval($timepart * pow(60, $exponent));
$exponent++;
}
return $seconds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment