just me and php Posted December 16, 2006 Share Posted December 16, 2006 Heres My ProblemUsers Are Posting Race Times To My Database Then I Have That Output To A php Page And It All Works Great, With A Lot Of Help From You Guys.New Problem , I Guess Different Countrys Post Different Number Formats Or Something Like That So Now Im Getting This.0:51,96 lap time 1:19,19 0:35,36 Is There A Code That Would Change The ,,,,, To ..... So It Looks Like This 0:08.33 lap time0:02.62 1:09.23 I Would Like To Change It In My php Page So I Dont Need To Mess With Database Or The Input Script To Database.Thanks Link to comment https://forums.phpfreaks.com/topic/30901-solved-help-please-to-change-to-solved-thanks/ Share on other sites More sharing options...
JP128 Posted December 16, 2006 Share Posted December 16, 2006 [code]<?php$period = '.';$string = "1:19,19";$string = ereg_replace('.', $period, $string);echo $string; /* Output: '1:19.19' */?>[/code] Link to comment https://forums.phpfreaks.com/topic/30901-solved-help-please-to-change-to-solved-thanks/#findComment-142548 Share on other sites More sharing options...
kenrbnsn Posted December 16, 2006 Share Posted December 16, 2006 Use the [url=http://www.php.net/str_replace]str_replace()[/url] function:[code]<?php$str = '1:19,19';$str = str_replace(',','.',$str);echo $str;?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/30901-solved-help-please-to-change-to-solved-thanks/#findComment-142552 Share on other sites More sharing options...
boby Posted December 16, 2006 Share Posted December 16, 2006 You can use [url=http://www.php.net/manual/en/function.preg-replace.php]preg_replace[/url] to replace all occurences of "," with "."Here is a little example:[code=php]<?php//Your lap time, get it from DB or whatever$time = '0:51,96 lap time';//Remplace "," (comma) with "." (dot)//Multiple commas are trimmed down to one dot$time = preg_replace ('#,+#', '.', $time);echo $time;?>[/code]I hope this is what you're looking for.BTW, the above will replace multiple commas with just one dot.[b]0:51,,,,,,,,,,,,96 lap time[/b] will result [b]0:51.96 lap time[/b]Boby Link to comment https://forums.phpfreaks.com/topic/30901-solved-help-please-to-change-to-solved-thanks/#findComment-142553 Share on other sites More sharing options...
Nicklas Posted December 16, 2006 Share Posted December 16, 2006 As [b]kenrbnsn[/b] suggest, use [i]str_replace()[/i] instead. There´s no need for regular expressions. Link to comment https://forums.phpfreaks.com/topic/30901-solved-help-please-to-change-to-solved-thanks/#findComment-142560 Share on other sites More sharing options...
just me and php Posted December 16, 2006 Author Share Posted December 16, 2006 Wow Thanks Guys I Got It To Work :) Link to comment https://forums.phpfreaks.com/topic/30901-solved-help-please-to-change-to-solved-thanks/#findComment-142569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.