同様に、この質問のタイトルの 2 番目の部分が存在しなければ、これを実行できたはずです。
$string = 'Hello,this is my string.';
$replacedstring = str_replace(',', ', ', $string);
しかし、ユーザーが のように文を正しくフォーマットした場合はどうなるでしょうかHello, this is my string.
。その結果、 になりHello, this is my string.
たくありません。
preg_replace
では、 PHP で および同様の正規表現関数を使用してそれを行うにはどうすればよいでしょうか?