$_GET['search']
导入以下字符串:“ first second \ \ third
”(“second”和“third”之间的空格只是空格,添加斜线是因为 SO 的文本区域不允许多个连续的空格)。
然后以下脚本将处理导入的字符串:
$searchString = $_GET['search'];
$searchString = preg_replace('/(\W)(\S)(\s+)/', '', $searchString);
echo $searchString . ' ';
print_r( explode(' ', $searchString) );
奇怪的是,这会导致:
first second third Array ( [0] => first [1] => second [2] => [3] => [4] => third )
即,正如预期的那样,空格从$searchString
when echo
ing 中删除,但 PHPexplode
似乎“重新插入”了它们。怎么会这样?