替换.用,在一个字符串中

pla*_*t x -1 php string replace

我一直在尝试使用preg_replace将字符串中的句点替换为逗号.

例如,

<?php
$string = "Hey you.";
$new_string = preg_replace("/./", ",", $new_string);
echo $new_string;
?>
Run Code Online (Sandbox Code Playgroud)

我确实在这里有一个错误,因为我对模式很困惑.任何见解?谢谢.

Dog*_*ert 6

使用 str_replace

$new_string = str_replace(".", ",", $new_string);
Run Code Online (Sandbox Code Playgroud)

你的正则表达式的问题是你没有逃脱.,并.匹配任何角色.

你可以这样做

$new_string = preg_replace("/\./", ",", $new_string);
Run Code Online (Sandbox Code Playgroud)