我有字符串
10.2、200.3、33.00
我希望它被替换为
10,2, 200,3, 33,00
我试过了
preg_replace("/[.]$/","/\d[,]$/",$input);
但它没有取代!
我不能使用str_replace
,因为这是大学的任务
str_replace()
当哑巴就足够时,不要使用正则表达式:
$str = str_replace('.', ',', $str)
请参阅文档: http: //php.net/str_replace
preg_replace('/\./', ',', $input);
这将取代所有的“。” 带有“,”的点。
preg_replace('/(\d+).(\d+)/', '$1,$2', $input);
这更符合您的需求。$1 替换括号中的第一个数字;2 美元秒。
-给我买一杯啤酒;)
你可以试试这个
preg_replace('/[^0-9\s]/', ',', $input)
但如果你使用它会更好
str_replace('.', ',', $input)
正如马尔辛回答的那样。