just me and php Posted February 8, 2007 Share Posted February 8, 2007 from a table in my database i get a set of numbers like this 1. 10:06.52 2. 10:06.93 3. 10:10.54 4. 11:18.65 5. 7:52.39 6. 8:01.51 7. 8:37.37 8. 8:41.01 9. 8:43.79 10. 9:05.03 11. 9:17.96 12. 9:19.29 13. 9:23.45 14. 9:25.03 15. 9:25.78 16. 9:33.70 but i would like it to be this 1. 07:52.39 2. 08:01.51 3. 08:37.37 4. 08:41.01 5. 08:43.79 6. 09:05.03 7. 09:17.96 8. 09:19.29 9. 09:23.45 10. 09:25.03 11. 09:25.78 12. 09:33.70 13. 10:06.52 14. 10:06.93 15. 10:10.54 16. 11:18.65 is there a way i could add an if (statement) or something in my sqlquery ??to add a 0 in front of all numbers below 10:00.00 Link to comment https://forums.phpfreaks.com/topic/37631-add-0-to-a-set-of-numbers-under-100000-like-099999/ Share on other sites More sharing options...
sayedsohail Posted February 8, 2007 Share Posted February 8, 2007 yes you can use functions like strpos strlen http://www.phpbuilder.com/manual/en/function.strlen.php Link to comment https://forums.phpfreaks.com/topic/37631-add-0-to-a-set-of-numbers-under-100000-like-099999/#findComment-180007 Share on other sites More sharing options...
just me and php Posted February 8, 2007 Author Share Posted February 8, 2007 hmm that example i dont understand how it could be used to add a 0 in front of numbers below 10:00.00 like 09:99.99 <?php $str = 'abcdef'; echo strlen($str); // 6 $str = ' ab cd '; echo strlen($str); // 7 ?> Link to comment https://forums.phpfreaks.com/topic/37631-add-0-to-a-set-of-numbers-under-100000-like-099999/#findComment-180012 Share on other sites More sharing options...
sayedsohail Posted February 8, 2007 Share Posted February 8, 2007 <?php $str ="0.1.1"; if (strlen($str) ==5) { echo "0$str";} // 6 ?> Link to comment https://forums.phpfreaks.com/topic/37631-add-0-to-a-set-of-numbers-under-100000-like-099999/#findComment-180019 Share on other sites More sharing options...
offsprg01 Posted February 8, 2007 Share Posted February 8, 2007 if (strlen($str) == 7) {$str = '0'.$str;} or something like that. Link to comment https://forums.phpfreaks.com/topic/37631-add-0-to-a-set-of-numbers-under-100000-like-099999/#findComment-180021 Share on other sites More sharing options...
just me and php Posted February 8, 2007 Author Share Posted February 8, 2007 PERFECT Thanks offsprg01 That Works Great Link to comment https://forums.phpfreaks.com/topic/37631-add-0-to-a-set-of-numbers-under-100000-like-099999/#findComment-180027 Share on other sites More sharing options...
kenrbnsn Posted February 8, 2007 Share Posted February 8, 2007 Try this: <?php function zerofill($str) { list($part1,$part2) = explode(':',$str); return(sprintf("%02d:%s",$part1,$part2)); } $temp = array(); $teststrs = array('7:52.39','10:10.54','11:18.65','8:01.51','8:37.37','8:41.01','9:43.79'); foreach($teststrs as $test) $temp[] = zerofill($test); sort($temp); echo '<pre>' . print_r($temp,true) . '<pre>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/37631-add-0-to-a-set-of-numbers-under-100000-like-099999/#findComment-180031 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.