Was
pizza1 pizza2 pizza3 pizza4
supposed to be
pizza1 pizza2 pizza3 pizza4
Anyway, your only good option to do this in a generic fashion is with regexp. Otherwise you'd have to
# on every iteration, check the string for occurence of more than one
# consecutive white space
while(strpos(' ', $str) !== false) {
# replace each sequence of two whitespaces with one whitespace
$str = str_replace(' ', ' ', $str);
}
And the reason the above is silly, assume this is your input
$str = '1 2';
And besides, the regexp approach is so simple
$p = '#[ ]+#';
$str = preg_replace($p, ' ', $str);