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
$va
Try this option:
$var = "hello, welcome, , , , ,"; $output = preg_replace('/,\s(?=[,])|,$/', '', $var); hello, welcome
Demo
This uses a lookahead to target only commas that are followed by a space and a comma, or by the end of the string.