Replace 2 commas separated by space with space using php
问题 Hi friends am trying to replace two commas separated by space with space using php. Here is my code Suppose for example am having variable like $var = "hello, welcome, , , ," Am using the below code to replace the commas in the above string. $output = preg_replace('/[,\s]+/', ' ', $var); Am getting the following output when am executing the above code hello welcome My required output is hello, welcome Can anyone help me with the above code 回答1: The pattern that you intend to replace is a