0

Possible Duplicate:
Replacing excess whitespaces

When I trim using PHP It just trim left and right side of PHP. Isn't their any function that remove more than 2 white spaces between a string?

Suppose I have this

"Stack       Overflow"

and I want this

"Stack Overflow"
Community
  • 1
  • 1
Rahul Singh
  • 1,596
  • 6
  • 21
  • 39

3 Answers3

2

How about this:

function fullTrim($str)
{
    return trim(preg_replace('/\s+/', ' ', $str));
}
JRL
  • 74,629
  • 18
  • 94
  • 144
0

You should do exactly what is described here: Replacing excess whitespaces Anyway, this question has been asked several times, you should have checked before submitting it.

Community
  • 1
  • 1
lc2817
  • 3,682
  • 15
  • 37
0
function customTrim($str)
{
   while(strpos($str,"  "))
   {
     $str = str_replace("  ", " ", $str);
   }
   return $str;
}

easy and understandable for beginners.

Regards

CoreCoder
  • 379
  • 1
  • 4
  • 14