我有以下字符串 + Example + Test + Test2
并使用 preg_replace 我想得到以下结果 +Example +Test +Test2
我一直在尝试使用以下代码
preg_replace("/\s*([\+])\s*/", "$1", $string)
但是这个正在返回
+Example+Test+Test2
最佳答案
$output = str_replace('+ ', '+', $input);
或
$output = preg_replace('/\\+\\s+/', '+', $input);
关于php - 在php中使用preg_replace删除php中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11542510/