Re: how to replace many spaces with one space?

From: Date: Sun, 25 Oct 2009 16:28:20 +0000
Subject: Re: how to replace many spaces with one space?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-299322@lists.php.net to get a copy of this message
On Sun, 2009-10-25 at 16:59 +0100, David Otton wrote: > 2009/10/25 Jeffry Lunggot <jeffry@rogon.com.my>: > > 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

« previous php.general (#299322) next »