在php中使用preg_replace删除php中的空间
我有以下字符串在php中使用preg_replace删除php中的空间,php,regex,preg-replace,Php,Regex,Preg Replace,我有以下字符串+Example+Test+Test2,使用preg_replace我希望得到以下结果+Example+Test+Test2 我一直在尝试使用以下代码 preg_replace("/\s*([\+])\s*/", "$1", $string) 但这一次又回来了 +Example+Test+Test2 或 +前面有多个空格呢?我知道Q没有说它(但它暗示了它)。只是恶作剧:)$output=trim(preg_replace('/\s*+\s*/','+',$input)); $o
+Example+Test+Test2
,使用preg_replace我希望得到以下结果+Example+Test+Test2
我一直在尝试使用以下代码
preg_replace("/\s*([\+])\s*/", "$1", $string)
但这一次又回来了
+Example+Test+Test2
或
+前面有多个空格呢?我知道Q没有说它(但它暗示了它)。只是恶作剧:)$output=trim(preg_replace('/\s*+\s*/','+',$input));
$output = str_replace('+ ', '+', $input);
$output = preg_replace('/\\+\\s+/', '+', $input);