Martti, resurrecting this question because it had a simple solution that lets you do the replace in one go—no need for implode. (Found your question while doing some research for a general question about how to exclude patterns in regex.)
Here's our simple regex:
"[^"]*"(*SKIP)(*F)|\s+
The left side of the alternation matches complete "quoted strings"
then deliberately fails. The right side matches whitespace characters, and we know they are the right whitespace characters because they were not matched by the expression on the left.
This code shows how to use the regex (see the results at the bottom of the online demo):
<?php
$regex = '~"[^"]*"(*SKIP)(*F)|\s+~';
$subject = 'hola hola "pepsi cola" yay';
$replaced = preg_replace($regex,"",$subject);
echo $replaced."<br />\n";
?>
Reference
How to match (or replace) a pattern except in situations s1, s2, s3...