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);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…