Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #4715

Re: reduce all spaces to one

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!not-for-mail
From "M. Strobel" <sorry_no_mail_here@nowhere.dee>
Newsgroups comp.lang.php
Subject Re: reduce all spaces to one
Date Fri, 03 Feb 2012 21:19:39 +0100
Lines 38
Message-ID <9p2tqsF5llU1@mid.uni-berlin.de> (permalink)
References <jghb1o$62h$1@speranza.aioe.org> <jghd0m$tvr$1@dont-email.me> <jghen802gga@news1.newsguy.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de AM43g4e+HWjB2cObDG12hA3gahA5tRNfMzyY6YcPElGQ2aGw4=
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.24) Gecko/20111101 Thunderbird/3.1.16
In-Reply-To <jghen802gga@news1.newsguy.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.php:4715

Show key headers only | View raw


Am 03.02.2012 21:05, schrieb crankypuss:
> On 02/03/2012 12:36 PM, Jerry Stuckle wrote:
>> On 2/3/2012 2:03 PM, John wrote:
>>> Hello everybody,
>>>
>>> what would be in PHP the equivalent of the VB .NET statement
>>>
>>> Text = Regex.Replace(Text, "[ ]+", " ")
>>>
>>> in order to reduce to one all the spaces between words (chr(32)) ???
>>>
>>> Thanks for the hints.
>>>
>>>
>>
>> Try
>>
>> $text = preg_replace('/\s+/', ' ', $text);
> 
> or,
> 
>     $text = str_replace("  ", " ", $text);
> 

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.

/Str.

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

reduce all spaces to one John <john_takethisoff@agdp.de> - 2012-02-03 20:03 +0100
  Re: reduce all spaces to one Jerry Stuckle <jstucklex@attglobal.net> - 2012-02-03 14:36 -0500
    Re: reduce all spaces to one crankypuss <no@email.thanks> - 2012-02-03 13:05 -0700
      Re: reduce all spaces to one Jerry Stuckle <jstucklex@attglobal.net> - 2012-02-03 15:17 -0500
      Re: reduce all spaces to one "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-02-03 21:19 +0100
        Re: reduce all spaces to one John <john_takethisoff@agdp.de> - 2012-02-03 21:59 +0100
          Re: reduce all spaces to one Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-04 15:41 +0100
            Re: reduce all spaces to one Jerry Stuckle <jstucklex@attglobal.net> - 2012-02-04 09:57 -0500
              Re: reduce all spaces to one Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-04 16:05 +0100
              Re: reduce all spaces to one Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-04 16:21 +0100
                Re: reduce all spaces to one Jerry Stuckle <jstucklex@attglobal.net> - 2012-02-04 16:00 -0500
              Re: reduce all spaces to one Michael Fesser <netizen@gmx.de> - 2012-02-05 21:47 +0100
                Re: reduce all spaces to one Jerry Stuckle <jstucklex@attglobal.net> - 2012-02-05 16:12 -0500
                Re: reduce all spaces to one "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-02-05 22:23 +0100
                Re: reduce all spaces to one The Natural Philosopher <tnp@invalid.invalid> - 2012-02-05 21:37 +0000
                Re: reduce all spaces to one Michael Fesser <netizen@gmx.de> - 2012-02-05 23:34 +0100
            Re: reduce all spaces to one John <john_takethisoff@agdp.de> - 2012-02-04 22:26 +0100
              Re: reduce all spaces to one Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-05 00:05 +0100
                Re: reduce all spaces to one John <john_takethisoff@agdp.de> - 2012-02-05 01:39 +0100
                Re: reduce all spaces to one Jerry Stuckle <jstucklex@attglobal.net> - 2012-02-04 20:56 -0500
                Re: reduce all spaces to one John <john_takethisoff@agdp.de> - 2012-02-05 18:02 +0100
                Re: reduce all spaces to one Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-05 03:15 +0100
                Re: reduce all spaces to one John <john_takethisoff@agdp.de> - 2012-02-05 18:04 +0100
                Re: reduce all spaces to one Doug Miller <doug_at_milmac_dot_com@example.com> - 2012-02-05 04:02 +0000
                Re: reduce all spaces to one Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-05 05:35 +0100
                Re: reduce all spaces to one Doug Miller <doug_at_milmac_dot_com@example.com> - 2012-02-06 01:31 +0000
                Re: reduce all spaces to one "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-02-06 09:31 +0100
                [OT]: "native" English (was: reduce all spaces to one) Gregor Kofler <usenet@gregorkofler.com> - 2012-02-05 11:03 +0100
                Re: [OT]: "native" English The Natural Philosopher <tnp@invalid.invalid> - 2012-02-05 10:11 +0000
                Re: [OT]: "native" English Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-05 14:00 +0100
                Re: [OT]: "native" English The Natural Philosopher <tnp@invalid.invalid> - 2012-02-05 13:53 +0000
                Re: reduce all spaces to one John <john_takethisoff@agdp.de> - 2012-02-05 18:05 +0100
  Re: reduce all spaces to one "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-02-03 21:30 +0100

csiph-web