I have string
10.2, 200.3, 33.00
and I want it to be replaced as
10,2, 200,3, 33,00
I tried
preg_replace("/[.]$/","/\d[,]$/",$input);
but it is not replacing!
I can't use str_replace
because it's task in university
I have string
10.2, 200.3, 33.00
and I want it to be replaced as
10,2, 200,3, 33,00
I tried
preg_replace("/[.]$/","/\d[,]$/",$input);
but it is not replacing!
I can't use str_replace
because it's task in university
Do not use regular expresion when dumb str_replace()
suffices:
$str = str_replace('.', ',', $str)
See docs: http://php.net/str_replace
preg_replace('/\./', ',', $input);
This would replace all .
dots with ,
.
preg_replace('/(\d+).(\d+)/', '$1,$2', $input);
This is more specific to your need. $1
replaces first digit as in parenthesis; $2
replaces second.
You can try this
preg_replace('/[^0-9\s]/', ',', $input)
but it is better if you use
str_replace('.', ',', $input)
as Marcin answered.