I’ve been trying to use preg_replace to replace period within my string to comma.
For example,
<?php
$string = "Hey you.";
$new_string = preg_replace("/./", ",", $new_string);
echo $new_string;
?>
I do have an error in here in which I am aware, because I am quite confused with patterns. Any insights? Thanks.
Use
str_replaceThe problem with your regex is that you haven’t escaped the
., and.is matching any character.You can do this