$word = 'bla   bla1      bla2         bla3';
while(strstr($word, '  ')) { // two blank spaces
   str_replace('  ', ' ', $word); //replace two blank space with one
}
// do it until there remove all double or more blank spaces between words

I intend to get $word='bla bla1 bla2 bla3' but this is going into a loop.
Thanks for help.

Found the error:

$word = str_replace('  ', ' ', $word);

    Generally, regular expression would make things simpler here, e.g.,

    $word = 'bla   bla1      bla2         bla3';
    $word = preg_replace('/ {2,}/', ' ', $word);

    or if you actually intend to replace one or more occurrences of consecutive whitespace with a space:

    $word = 'bla   bla1      bla2         bla3';
    $word = preg_replace('/\s+/', ' ', $word);

      Thanks laserlight for this complement!

        Write a Reply...