Jump to content

[SOLVED] Help Please , To Change , to . ( SOLVED) Thanks


just me and php

Recommended Posts

Heres My Problem
Users 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 time
0: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
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.