日期:2014-05-17 浏览次数:20476 次
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"', ' ', '