How can I replace all commas followed by spaces (", "
) with just commas (","
)?
I don't want to replace spaces when they don't have a comma in front of them (" "
).
All the str_replace solutions will work. If you want to replace all whitespaces before and after the commas
$str = 'cat, dog , cow, horse ,mouse,moose';
$pattern = '/\s*,\s*/';
$replace = ',';
$str = preg_replace($pattern, $replace, $str);
This should do the trick:
$str = "some, comma, seperated, words";
$str = str_replace(", ", ",", $str);
This will do the trick?
$sString = str_replace(", ", ",", $sString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With