android6011 Posted June 8, 2007 Share Posted June 8, 2007 Ok, I have a variable named length, the variable outputs something such as 4:06 . What I want to do is have the page refresh after that length, but the meta tag needs seconds. I know how to do the math portion of it, im just not sure how to break it up so I can get the 4 and the 06 separate. thanks Link to comment https://forums.phpfreaks.com/topic/54801-break-up-a-string-into-integers/ Share on other sites More sharing options...
kenrbnsn Posted June 8, 2007 Share Posted June 8, 2007 Use the explode() funciton: <?php $str = '4:06'; list ($min,$sec) = explode(':',$str); $secs = ($min * 60) + $sec; echo $secs; ?> Ken Link to comment https://forums.phpfreaks.com/topic/54801-break-up-a-string-into-integers/#findComment-271015 Share on other sites More sharing options...
android6011 Posted June 8, 2007 Author Share Posted June 8, 2007 thanks Link to comment https://forums.phpfreaks.com/topic/54801-break-up-a-string-into-integers/#findComment-271107 Share on other sites More sharing options...
obsidian Posted June 9, 2007 Share Posted June 9, 2007 I think kenrbnsn has the best solution, but if you ever have a string where you have a number of integers, and you simply want to extract them all, you could do something like this, and you wouldn't have to worry about what the separators were: <?php if (preg_match_all('|\d+|', $string, $matches)) { foreach ($matches[0] as $x) { echo "Found $x<br />\n"; } } ?> Link to comment https://forums.phpfreaks.com/topic/54801-break-up-a-string-into-integers/#findComment-271221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.