Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <3167694.MM0jWc37uj@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 04 Feb 2012 16:05:49 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit Subject: Re: reduce all spaces to one Newsgroups: comp.lang.php References: <9p2tqsF5llU1@mid.uni-berlin.de> <3604821.WhU2xvQL5g@PointedEars.de> Followup-To: comp.lang.php MIME-Version: 1.0 Lines: 56 NNTP-Posting-Date: 04 Feb 2012 16:05:50 CET NNTP-Posting-Host: e69d49ac.newsspool1.arcor-online.net X-Trace: DXC=nJ;PfYA3ZERU6b:FjPaGjQic==]BZ:af^4Fo<]lROoRQ<`=YMgDjhgRkCF7l1W35VUDZm8W4\YJN\b@mF9jNikdUUGYSN30J3H^mHaSYIh9i8\ X-Complaints-To: usenet-abuse@arcor.de Xref: x330-a1.tempe.blueboxinc.net comp.lang.php:4720 Jerry Stuckle wrote: > On 2/4/2012 9:41 AM, Thomas 'PointedEars' Lahn wrote: >> John wrote: >>> Am 03.02.2012 21:19, schrieb M. Strobel: >>>> Solution shootout: >>>> strobel@s114-intel:~> php -a >>>> Interactive shell >>>> >>>> php> echo str_replace(' ',' ','here are some spaces '); >>>> here are some spaces >>>> php> echo preg_replace('/\s+/', ' ', 'here are some spaces >>>> '); here are some spaces >>>> php> >>>> >>>> The regex solution is the winner. >>> OK. Thanks to all those who answered !! >> >> It should be noted that if your question was understood literally, the >> solutions presented so far would be wrong. \s would match too many >> different characters, as it stands for *white-space* in PCRE, _not_ only >> the space character. In order to reduce only all consecutive *space* >> characters to one space character, you need to write >> >> echo preg_replace('/ +/', ' ', "here are some \n spaces "); >> >> Note that the newline, which is white-space too, is preserved here. > > Newline is preserved in my version also, No, it is not. $ php -a Interactive mode enabled if you understood ANYTHING about how PHP's regex's work (but we already > know you don't). Stop talking to the mirror. PointedEars -- var bugRiddenCrashPronePieceOfJunk = ( navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1 ) // Plone, register_function.js:16