正则表达式多余空格怎么去掉?
echo $keyword = "上海|北京!成都 深圳";
echo "<br />";
$old1 = array("/(\s*)(\s)(\s*)/","/(\s*)(\|)(\s*)/","/(\s*)(!)(\s*)/");
$new1 = array('" "','"|"','" "!');
echo $keyword3=""".preg_replace($old1,$new1,$keyword).""";
//输出:"上海"|"北京" "!成都" "深圳"
echo $keyword = "上海 | 北京 !成都 深圳";
echo "<br />";
$old1 = array("/(\s*)(\s)(\s*)/","/(\s*)(\|)(\s*)/","/(\s*)(!)(\s*)/");
$new1 = array('" "','"|"','" "!');
echo $keyword3=""".preg_replace($old1,$new1,$keyword).""";
//输出:"上海" ""|"" "北京" "" "!成都" "深圳"
echo $keyword = "上海
[解决办法]
北京!成都 深圳";
echo "<br />";
$old1 = array("/(\s*)(\s)(\s*)/","/(\s*)(\
[解决办法]
)(\s*)/","/(\s*)(!)(\s*)/");
$new1 = array('" "','"
[解决办法]
"','" "!');
echo $keyword3=""".preg_replace($old1,$new1,$keyword).""";
//输出:"上海"
[解决办法]
"北京" "!成都" "深圳"
echo $keyword = "上海
[解决办法]
北京 !成都 深圳";
$keyword = str_replace(" ","",$keyword);
echo "<br />";
$old1 = array("/(\s*)(\s)(\s*)/","/(\s*)(\
[解决办法]
)(\s*)/","/(\s*)(!)(\s*)/");
$new1 = array('" "','"
[解决办法]
"','" "!');
echo $keyword3=""".preg_replace($old1,$new1,$keyword).""";
//输出:"上海" ""
[解决办法]
"" "北京" "" "!成都" "深圳"
$keyword = "上海
[解决办法]
北京!成都 深圳"; //输出:"上海"
[解决办法]
"北京" "!成都" "深圳"
$keyword = "上海
[解决办法]
北京 !成都 深圳";//输出:"上海"
[解决办法]
"北京" "!成都" "深圳"
echo "<br />";
$old1 = array("/!?[^\s!
[解决办法]
]+/", "/\s+/", "/\s*\
[解决办法]
\s*/", '/""/');
$new1 = array('"$0"', ' ', '
[解决办法]
', '" "');
echo $keyword3 = preg_replace($old1,$new1,$keyword);
$old1 = array("/(\s*)(\
[解决办法]
)(\s*)/","/(\s*)(!)(\s*)/","/(\s*)(\s)(\s*)(?!")/");
$new1 = array('"
[解决办法]
"','" "!','" "');
echo $keyword = "上海
[解决办法]
北京 !成都 深圳";
$keyword = str_replace(" ","",$keyword);
echo "<br />";
$old1 = array("/(\s*)(\
[解决办法]
)(\s*)/","/(\s*)(!)(\s*)/","/(\s*?)(\s)(\s*?)/");
$new1 = array('"
[解决办法]
"','" "!','" "');
echo $keyword3=""".preg_replace($old1,$new1,$keyword).""";
//输出:"上海" ""
[解决办法]
"" "北京" "" "!成都" "深圳"