Re: how to replace many spaces with one space?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2009-10-25 at 16:59 +0100, David Otton wrote:

> 2009/10/25 Jeffry Lunggot <jeffry@xxxxxxxxxxxx>:
> > Hi,
> >
> > how to replace many spaces in any string of character with  one space?
> 
> $str = preg_replace('/\s\s+/', ' ', $str);
> 


$str = preg_replace('/\s+/', ' ', $str);

You don't need both space characters, as the + symbol matches one or
more, which is just what you want.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux