2011-06-09 212 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);