[thelist] Replacing periods with commas

ftarzwell at fayec.com ftarzwell at fayec.com
Fri Jan 4 07:49:23 CST 2008


>>On Jan 3, 2008 1:16 PM,  <ftarzwell at fayec.com> wrote:
>>
>> I have an output file that should display:
>> 864,7 $    +8.2
>> Instead it's showing:
>> 86,.7 $    +,.2
>>
>> The code that does the replacement of the period for a comma is as
follows:
>> $change = substr_replace($change, ",", strlen($change) - 3, 1);
>>
>> Should the code be:
>> $change = substr_replace($change, ",", strlen($change) - 2, 1);
>>
>> in order to fix the comma issue?
>
>Actually, I'd use strtr (http://php.net/strtr) instead:
>
>$change = strtr($change, ',' , '.');
>
>That way you never have to worry about how many digits are in the number.
>
>Brady

Hi Brady,

Thank you for the help. Will using this alternate way mess up the rest of
the code?
Also, based on the php.net page it should be $change, "string $from",
"string $to".
In this case should I write ($change, '.', ',') ??

Thanks,
 FayeC




More information about the thelist mailing list