Re: Is there a standard function to remove multiple spaces from a string?

From: Date: Fri, 09 Aug 2002 15:55:25 +0000
Subject: Re: Is there a standard function to remove multiple spaces from a string?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-111833@lists.php.net to get a copy of this message
function foo($str,$num) { return preg_replace('/ {'.$num.',}/',str_repeat(' ',$num),$str); } On Fri, 9 Aug 2002, Henry wrote: > Hi All, > > Are there standard functions for removing multiple spaces (or even better > limiting contiguous space to specified lengths)? > > i.e > > foo("Hello peeps, happy times",1) -> "Hello peeps, happy times" > foo("Hello peeps, happy times",0) -> "Hellopeeps,happytimes" > foo("Hello peeps, happy times",2) -> "Hello peeps, happy times" > (notice single space between "," and "h") > > Can I do it with reg exp? > > TIA > > Henry > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#111833) next »