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


Groups > comp.lang.php > #4739

Re: reduce all spaces to one

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: reduce all spaces to one
Date 2012-02-05 16:12 -0500
Organization A noiseless patient Spider
Message-ID <jgmrb7$80i$1@dont-email.me> (permalink)
References (3 earlier) <9p2tqsF5llU1@mid.uni-berlin.de> <jghhqd$nh0$1@speranza.aioe.org> <3604821.WhU2xvQL5g@PointedEars.de> <jgjh1d$lbc$1@dont-email.me> <5loti75nc9gnh910mga0rv308gohmft1p7@mfesser.de>

Show all headers | View raw


On 2/5/2012 3:47 PM, Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
>> On 2/4/2012 9:41 AM, Thomas 'PointedEars' Lahn wrote:
>>>
>>> Note that the newline, which is white-space too, is preserved here.
>>>
>>
>> Newline is preserved in my version also, if you understood ANYTHING
>> about how PHP's regex's work (but we already know you don't).
>
> You want to read the manual and not start a flame war everytime you
> answer to a person you don't like.
>
> By default \s also matches LF and CR, because internally the C library
> function isspace() function is used:
>
> http://www.cplusplus.com/reference/clibrary/cctype/isspace/
>
>> It also
>> takes out tabs - which may be inserted automatically by some editors,
>> for instance, and can be desirable.
>
> Correct, but the OP didn't ask for that.
>
>>> If you want to make the space character in the expression better visible,
>>> you can use
>>>
>>>     (1) echo preg_replace('/\ +/', ' ', "here   are  some  \n   spaces  ");
>>>
>>
>> The search pattern is invalid.
>
> No. You can escape every char you want, even if it's not necessary.
>
>>> or
>>>
>>>     (2) echo preg_replace('/\\ +/', ' ', "here   are  some  \n   spaces  ");
>>>
>>
>> Searches for the sequence '\ '
>
> No. The double backslash is handled by PHP (see escaping in single-
> quoted strings), after then it's just like (1).
>
> BTW: If you want to match a backslash, you'd have to write '\\\\' in the
> pattern.
>
>>> or
>>>
>>>     (3) echo preg_replace('/\x20+/', ' ', "here   are  some  \n   spaces  ");
>>>
>>
>> Ugh!
>
> Perfectly legal and sometimes the only way to define very special
> characters.
>
>>> or
>>>
>>>     (4) echo preg_replace('/\\x20+/', ' ', "here   are  some  \n   spaces  ");
>>>
>>
>> Again, invalid escape sequence.
>
> Again you're wrong, see (2).
>
>> Showing your ignorance again.  You do better when you keep your mouth shut.
>
> It's _you_ who should keep the mouth shut in cases like this, especially
> if obviously you didn't take the time to test the given examples, but
> call them invalid instead. But since they just use different escaping
> mechanisms in PHP and the PCRE engine, they're absolutely valid and
> useful in different cases.
>
> Micha
>

That's all we need - another troll in this newsgroup.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

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