2011-06-09 169 views

回答

17

所有str_replace函数解决方案将正常工作。如果要在逗号前后替换所有空白字符,请执行以下操作:

$str = 'cat, dog , cow,  horse ,mouse,moose'; 

$pattern = '/\s*,\s*/'; 
$replace = ','; 
$str = preg_replace($pattern, $replace, $str); 
+0

这是真正的答案! – 2013-09-14 02:11:12

2

这会做诡计吗?

$sString = str_replace(", ", ",", $sString); 
2

你可以这样做:

$str = str_replace(', ',',',$str); 
6

这应该做的伎俩:

$str = "some, comma, seperated, words"; 
$str = str_replace(", ", ",", $str);