2
删除的空间,我有以下字符串+ Example + Test + Test2
和使用的preg_replace我希望得到以下结果+Example +Test +Test2
在PHP中使用的preg_replace在PHP
我一直在尝试使用下面的代码
preg_replace("/\s*([\+])\s*/", "$1", $string)
但是这一个是返回
+Example+Test+Test2
删除的空间,我有以下字符串+ Example + Test + Test2
和使用的preg_replace我希望得到以下结果+Example +Test +Test2
在PHP中使用的preg_replace在PHP
我一直在尝试使用下面的代码
preg_replace("/\s*([\+])\s*/", "$1", $string)
但是这一个是返回
+Example+Test+Test2
$output = str_replace('+ ', '+', $input);
或
$output = preg_replace('/\\+\\s+/', '+', $input);
那么+之前的多个空格呢?我知道Q并没有这样说(但它暗示了它)。只是调皮:) – Pete 2012-07-18 13:36:41
$ output = trim(preg_replace('/ \ s * + \ s * /','+',$ input)); – Ron 2012-07-18 13:38:22