可能重复:
Replace comma + space with “,” but not spaces without commas逗号之前或之后删除空格在PHP
这里是我的文字
$x = 'first name, middle name, last name';
期望输出
first name,middle name,last name
试过这种
$x = str_replace(array(', ', ' ,', ' , '), array(',', ',', ','), $x);
我不知道这样的方式
预期的行为:告诉我们你已经尝试了什么。即使这是意想不到的,你会得到什么结果? – 2012-02-17 19:15:11
*我不确定这种方式*:它适合你吗? – 2012-02-17 19:19:14