$_GET['search']
imports the following string: "first second \ \ third
" (the spaces between "second" and "third" are just blank spaces, the slashes are added since SO's text area does not allow multiple consecutive blank spaces).
The following script is then to process the imported string:
$searchString = $_GET['search'];
$searchString = preg_replace('/(\W)(\S)(\s+)/', '', $searchString);
echo $searchString . ' ';
print_r( explode(' ', $searchString) );
Which, strangely, results in:
first second third Array ( [0] => first [1] => second [2] => [3] => [4] => third )
I.e. the blank spaces are removed, as anticipated, from $searchString
when echo
ing it, but PHP's explode
seems to "re-insert" them. How can this be?