View Full Version : Split a string like 8m45s in mins and secs
chrisvmarle
07-28-2003, 03:52 PM
Hi all,
I have a couple of strings (in an array) that contain minutes and seconds like this:
"8m45s", "5m12s", "11m04s", etc
Now I'd like to have the minutes put in $min and the seconds in $sec.
Does anyone know how to do this?
Thanks in advance
Laterz, Chris
There are hundreds of ways to do that...
Try this script:
<?
$var = "11m05s";
$values = explode("m", $var);
$min = intval($values[0]);
$sec = intval($values[1]);
echo "minutes: $min <br>Seconds: $sec";
?>
Saludo
piz
Jason
07-28-2003, 08:32 PM
you could do it a cheezy way like if you know time is military or something...so always two digits for hours and two digits for min giving something like
$time = 05m15s
$hour = "$time[0]"."$time[1]";
$min = "$time[3]"."$time[4]";
or a more complicated way
$time = 5m15s
list($hour, $min) = split("m",$time); //so it takes the time and splits it into two "arrays" giveing
$hour and min back
list($min, $blah) = split("s",$min); //chops the "s off of the time...
Jason
chrisvmarle
07-28-2003, 11:22 PM
Thanks, they both work, but the I choose the first :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.