Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中使用preg_replace删除php中的空间_Php_Regex_Preg Replace - Fatal编程技术网

在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);