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


Groups > comp.lang.php > #4711 > unrolled thread

reduce all spaces to one

Started byJohn <john_takethisoff@agdp.de>
First post2012-02-03 20:03 +0100
Last post2012-02-03 21:30 +0100
Articles 20 on this page of 33 — 9 participants

Back to article view | Back to comp.lang.php


Contents

  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

Page 1 of 2  [1] 2  Next page →


#4711 — reduce all spaces to one

FromJohn <john_takethisoff@agdp.de>
Date2012-02-03 20:03 +0100
Subjectreduce all spaces to one
Message-ID<jghb1o$62h$1@speranza.aioe.org>
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.

[toc] | [next] | [standalone]


#4712

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-02-03 14:36 -0500
Message-ID<jghd0m$tvr$1@dont-email.me>
In reply to#4711
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);


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

[toc] | [prev] | [next] | [standalone]


#4713

Fromcrankypuss <no@email.thanks>
Date2012-02-03 13:05 -0700
Message-ID<jghen802gga@news1.newsguy.com>
In reply to#4712
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);

[toc] | [prev] | [next] | [standalone]


#4714

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-02-03 15:17 -0500
Message-ID<jghfcf$cib$1@dont-email.me>
In reply to#4713
On 2/3/2012 3:05 PM, crankypuss wrote:
> 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);
>

Doesn't work - try it with 'abc    def    ghi    jkl'.

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

[toc] | [prev] | [next] | [standalone]


#4715

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-02-03 21:19 +0100
Message-ID<9p2tqsF5llU1@mid.uni-berlin.de>
In reply to#4713
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.

[toc] | [prev] | [next] | [standalone]


#4717

FromJohn <john_takethisoff@agdp.de>
Date2012-02-03 21:59 +0100
Message-ID<jghhqd$nh0$1@speranza.aioe.org>
In reply to#4715
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.
>
> /Str.

OK.  Thanks to all those who answered !!

[toc] | [prev] | [next] | [standalone]


#4718

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-02-04 15:41 +0100
Message-ID<3604821.WhU2xvQL5g@PointedEars.de>
In reply to#4717
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.

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  ");

or

  (2) echo preg_replace('/\\ +/', ' ', "here   are  some  \n   spaces  ");

or

  (3) echo preg_replace('/\x20+/', ' ', "here   are  some  \n   spaces  ");

or

  (4) echo preg_replace('/\\x20+/', ' ', "here   are  some  \n   spaces  ");

Your approach,

      echo preg_replace('/[ ]+/', ' ', "here   are  some  \n   spaces  ");

is equivalent to that, but slightly less efficient because of the character 
class (even in Visual Basic .NET).  However, it also has the advantage over 
the simple solutions (1) and (2) that multiple spaces in the character class 
will still only match one space.


PointedEars
-- 
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
  -- Richard Cornford, comp.lang.javascript, 2011-11-14

[toc] | [prev] | [next] | [standalone]


#4719

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-02-04 09:57 -0500
Message-ID<jgjh1d$lbc$1@dont-email.me>
In reply to#4718
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, if you understood ANYTHING 
about how PHP's regex's work (but we already know you don't).  It also 
takes out tabs - which may be inserted automatically by some editors, 
for instance, and can be desirable.

> 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.

> or
>
>    (2) echo preg_replace('/\\ +/', ' ', "here   are  some  \n   spaces  ");
>

Searches for the sequence '\ '

> or
>
>    (3) echo preg_replace('/\x20+/', ' ', "here   are  some  \n   spaces  ");
>

Ugh!

> or
>
>    (4) echo preg_replace('/\\x20+/', ' ', "here   are  some  \n   spaces  ");
>

Again, invalid escape sequence.

> Your approach,
>
>        echo preg_replace('/[ ]+/', ' ', "here   are  some  \n   spaces  ");
>
> is equivalent to that, but slightly less efficient because of the character
> class (even in Visual Basic .NET).  However, it also has the advantage over
> the simple solutions (1) and (2) that multiple spaces in the character class
> will still only match one space.
>
>
> PointedEars

Showing your ignorance again.  You do better when you keep your mouth shut.

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

[toc] | [prev] | [next] | [standalone]


#4720

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-02-04 16:05 +0100
Message-ID<3167694.MM0jWc37uj@PointedEars.de>
In reply to#4719
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

<?php

echo "|foo \n bar|";
echo preg_replace('/\s+/', ' ', "|foo \n bar|");     
echo preg_replace('/ +/', ' ', "|foo \n bar|");
|foo 
 bar||foo bar||foo 
 bar|

> 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

[toc] | [prev] | [next] | [standalone]


#4721

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-02-04 16:21 +0100
Message-ID<5276217.E221FIoCZi@PointedEars.de>
In reply to#4719
Ahh, there was more nonsense to be corrected …

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, if you understood ANYTHING
> about how PHP's regex's work (but we already know you don't). 

JFYI, with preg_* methods, PHP's Regular Expressions are *Perl-Compatible* 
Regular Expressions.  That is what the `p' stands for there (as opposed to 
ereg_*, which are now [PHP 5.3] deprecated methods using POSIX *E*xtended 
Regular Expressions).

>> 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.

Perfectly valid
 
$ php -v
PHP 5.3.10-1 (cli) (built: Feb  3 2012 10:03:01) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with XCache v1.3.2, Copyright (c) 2005-2011, by mOo
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

>> or
>>
>>    (2) echo preg_replace('/\\ +/', ' ', "here   are  some  \n   spaces 
>>    ");
>>
> 
> Searches for the sequence '\ '

Not in the PHP version mentioned above.

>> or
>>
>>    (3) echo preg_replace('/\x20+/', ' ', "here   are  some  \n   spaces 
>>    ");
>>
> 
> Ugh!

man 3 pcrepattern
 
>> or
>>
>>    (4) echo preg_replace('/\\x20+/', ' ', "here   are  some  \n   spaces 
>>    ");
>>
> 
> Again, invalid escape sequence.

Again, perfectly valid and working as intended in the PHP version mentioned 
above.  Probably valid in *all* PHP versions that support PCREs.  You have 
not bothered to do any tests before posting, have you?

>> Your approach,
>>
>>        echo preg_replace('/[ ]+/', ' ', "here   are  some  \n   spaces 
>>        ");
>>
>> is equivalent to that, but slightly less efficient because of the
>> character class (even in Visual Basic .NET).  However, it also has the
>> advantage over the simple solutions (1) and (2) that multiple spaces in
>> the character class will still only match one space.
> 
> Showing your ignorance again.  You do better when you keep your mouth
> shut.

Pot, kettle, black.


PointedEars
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

[toc] | [prev] | [next] | [standalone]


#4722

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-02-04 16:00 -0500
Message-ID<jgk6aa$fhl$1@dont-email.me>
In reply to#4721
On 2/4/2012 10:21 AM, Thomas 'PointedEars' Lahn wrote:
> Ahh, there was more nonsense to be corrected …
>
> 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, if you understood ANYTHING
>> about how PHP's regex's work (but we already know you don't).
>
> JFYI, with preg_* methods, PHP's Regular Expressions are *Perl-Compatible*
> Regular Expressions.  That is what the `p' stands for there (as opposed to
> ereg_*, which are now [PHP 5.3] deprecated methods using POSIX *E*xtended
> Regular Expressions).
>
>>> 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.
>
> Perfectly valid
>
> $ php -v
> PHP 5.3.10-1 (cli) (built: Feb  3 2012 10:03:01)
> Copyright (c) 1997-2012 The PHP Group
> Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
>      with XCache v1.3.2, Copyright (c) 2005-2011, by mOo
>      with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
>      with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
>
>>> or
>>>
>>>     (2) echo preg_replace('/\\ +/', ' ', "here   are  some  \n   spaces
>>>     ");
>>>
>>
>> Searches for the sequence '\ '
>
> Not in the PHP version mentioned above.
>
>>> or
>>>
>>>     (3) echo preg_replace('/\x20+/', ' ', "here   are  some  \n   spaces
>>>     ");
>>>
>>
>> Ugh!
>
> man 3 pcrepattern
>
>>> or
>>>
>>>     (4) echo preg_replace('/\\x20+/', ' ', "here   are  some  \n   spaces
>>>     ");
>>>
>>
>> Again, invalid escape sequence.
>
> Again, perfectly valid and working as intended in the PHP version mentioned
> above.  Probably valid in *all* PHP versions that support PCREs.  You have
> not bothered to do any tests before posting, have you?
>
>>> Your approach,
>>>
>>>         echo preg_replace('/[ ]+/', ' ', "here   are  some  \n   spaces
>>>         ");
>>>
>>> is equivalent to that, but slightly less efficient because of the
>>> character class (even in Visual Basic .NET).  However, it also has the
>>> advantage over the simple solutions (1) and (2) that multiple spaces in
>>> the character class will still only match one space.
>>
>> Showing your ignorance again.  You do better when you keep your mouth
>> shut.
>
> Pot, kettle, black.
>
>
> PointedEars

Your ability to state the obvious is only exceeded by your stoopidity 
and ability to confuse a simple issue.

No one here gives a damn about your ability to cut and paste answers 
just to try to prove you know something.  We know you don't - just like 
in other usenet newsgroups.

And we know that lack of appreciation for your stoopidity riles you to 
no end.

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

[toc] | [prev] | [next] | [standalone]


#4738

FromMichael Fesser <netizen@gmx.de>
Date2012-02-05 21:47 +0100
Message-ID<5loti75nc9gnh910mga0rv308gohmft1p7@mfesser.de>
In reply to#4719
.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

-- 
http://mfesser.de/blickwinkel

[toc] | [prev] | [next] | [standalone]


#4739

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-02-05 16:12 -0500
Message-ID<jgmrb7$80i$1@dont-email.me>
In reply to#4738
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
==================

[toc] | [prev] | [next] | [standalone]


#4740

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-02-05 22:23 +0100
Message-ID<9p8abfFdsaU1@mid.uni-berlin.de>
In reply to#4739
Am 05.02.2012 22:12, schrieb Jerry Stuckle:
> On 2/5/2012 3:47 PM, Michael Fesser wrote:
>> .oO(Jerry Stuckle)
>>

--cut
>>>
>>> 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.
> 

I can understand your grief - you want to be the only one. But calm down, you still are.

/Str.

[toc] | [prev] | [next] | [standalone]


#4742

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2012-02-05 21:37 +0000
Message-ID<jgmsrn$ges$3@news.albasani.net>
In reply to#4740
M. Strobel wrote:
> Am 05.02.2012 22:12, schrieb Jerry Stuckle:

>> That's all we need - another troll in this newsgroup.
>>
> 
> I can understand your grief - you want to be the only one. But calm down, you still are.
> 
> 

:-)

[toc] | [prev] | [next] | [standalone]


#4743

FromMichael Fesser <netizen@gmx.de>
Date2012-02-05 23:34 +0100
Message-ID<ca0ui7lo58q0q7r9peq3qufb5kdjhj1dlv@mfesser.de>
In reply to#4739
.oO(Jerry Stuckle)

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

I didn't attack you, I just corrected you. But it's as usual - you can't
admit you were wrong. Instead you're still insulting people without any
reason, as always. What about some on-topic comments about my posting?

Micha

-- 
http://mfesser.de/blickwinkel

[toc] | [prev] | [next] | [standalone]


#4723

FromJohn <john_takethisoff@agdp.de>
Date2012-02-04 22:26 +0100
Message-ID<jgk7qi$rgb$1@speranza.aioe.org>
In reply to#4718
Am 04.02.2012 15:41, schrieb Thomas 'PointedEars' Lahn:

>
> 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.
>

in fact, just by 'accident' the 'regex' solutions fits perfectly in what 
I have to do next, i.e. feed the text through an 'explode' statement, 
which takes ' ' as separator.

[toc] | [prev] | [next] | [standalone]


#4724

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-02-05 00:05 +0100
Message-ID<1669543.FqOfKyIYee@PointedEars.de>
In reply to#4723
John wrote:

> Am 04.02.2012 15:41, schrieb Thomas 'PointedEars' Lahn:
                       ^^^^^^^
>> 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.
> 
> in fact, just by 'accident' the 'regex' solutions fits perfectly in what
> I have to do next, i.e. feed the text through an 'explode' statement,
> which takes ' ' as separator.

I do not think you have fully understood what I have said (maybe you want to 
try posting to *de*.comp.lang.php instead?).  *All* presented solutions so 
far, including yours and mine, are "'regex' solutions".  But the set of 
characters that are replaced differs between them.

Anyhow, you do not need to replace spaces before word splitting.  Instead of 
PHP 5+ [1]

  $words = str_split(' ', preg_replace('/\\s+/', ' ', $text));

since PHP 4 you can just split at consecutive white-space [2]:

  $words = preg_split('/\\s+/', $text);

Also note that for finding the *words* in a text, this splitting at white-
space is _not_ sufficient.  For example, in the sentence before splitting at 
white-space would have resulted in words "text," "_not_", and "sufficient.".  
Once you use preg_split(), though, there is a simple remedy (which can be 
found at [2]).  Just include all characters that you do not want to be part 
of a word in the character class:

  $words = preg_split('/[\\s,]+/', $text);

(I prefer to write `\\' instead of `\' even within single-quoted strings, in 
order to make the `\' explicit.  YMMV.)

You might also want to exclude periods (`.') and other punctuation from 
words, like dashes and ellipses.  Note that PCRE provides an escape sequence 
for ASCII-non-word characters [3], and that it supports Unicode character 
properties, which can be used to differentiate between letters and non-
letters in various natural languages [4].

You might find [5] useful, in particular [6], for the next time that you 
post (translations are available there).


PointedEars
___________
[1] <http://php.net/str_split>
[2] <http://php.net/preg_split>
[3] <http://php.net/manual/en/regexp.reference.escape.php>
[4] <http://php.net/manual/en/regexp.reference.unicode.php>
[5] <http://catb.org/esr/faqs/smart-questions.html>
[6] <http://catb.org/esr/faqs/smart-questions.html#goal>
-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

[toc] | [prev] | [next] | [standalone]


#4725

FromJohn <john_takethisoff@agdp.de>
Date2012-02-05 01:39 +0100
Message-ID<jgkj4t$j9l$1@speranza.aioe.org>
In reply to#4724
Am 05.02.2012 00:05, schrieb Thomas 'PointedEars' Lahn:
>
> I do not think you have fully understood what I have said (maybe you want to
> try posting to *de*.comp.lang.php instead?).  *All* presented solutions so
> far, including yours and mine, are "'regex' solutions".  But the set of
> characters that are replaced differs between them.
>

Thanks for the suggestions and advice : however I hope my english is 
adequate enough to make myself understood in this NG :-))

>
>    $words = str_split(' ', preg_replace('/\\s+/', ' ', $text));
>

I have the problem of  'filtering' a text file, exported from Excel as a 
'Windows text file with <return>', containing <tabs> between numbers.
So, besides converting all comma to points, I have to get rid af all 
<tabs> and after that, reduce all spaces between words to one space.

So far its working : I have used the preg_split first with /\t/ then
/\s+/ in two separate steps. No problem so far.
If they arise, I'll come back again.

>
> You might also want to exclude periods (`.') and other punctuation from
> words,

I can't. I need the numbers and they may be decimals with points.

> You might find [5] useful, in particular [6], for the next time that you
> post (translations are available there).
>

Thanks very much indeed for the most exhaustive answer !  I am happy 
I've found this place.

Thanks and best regards to all who contributed to the thread.

John.

[toc] | [prev] | [next] | [standalone]


#4726

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-02-04 20:56 -0500
Message-ID<jgknjq$af2$1@dont-email.me>
In reply to#4725
On 2/4/2012 7:39 PM, John wrote:
> Am 05.02.2012 00:05, schrieb Thomas 'PointedEars' Lahn:
>>
>> I do not think you have fully understood what I have said (maybe you
>> want to
>> try posting to *de*.comp.lang.php instead?). *All* presented solutions so
>> far, including yours and mine, are "'regex' solutions". But the set of
>> characters that are replaced differs between them.
>>
>
> Thanks for the suggestions and advice : however I hope my english is
> adequate enough to make myself understood in this NG :-))
>
>>
>> $words = str_split(' ', preg_replace('/\\s+/', ' ', $text));
>>
>
> I have the problem of 'filtering' a text file, exported from Excel as a
> 'Windows text file with <return>', containing <tabs> between numbers.
> So, besides converting all comma to points, I have to get rid af all
> <tabs> and after that, reduce all spaces between words to one space.
>
> So far its working : I have used the preg_split first with /\t/ then
> /\s+/ in two separate steps. No problem so far.
> If they arise, I'll come back again.
>

The /\s+/ will also get rid of tabs, converting all white space to a 
single blank.

Perhaps a better option would be to export the file as a .csv and use 
fgetcsv().  It will save you a lot of work.


>>
>> You might also want to exclude periods (`.') and other punctuation from
>> words,
>
> I can't. I need the numbers and they may be decimals with points.
>
>> You might find [5] useful, in particular [6], for the next time that you
>> post (translations are available there).
>>
>
> Thanks very much indeed for the most exhaustive answer ! I am happy I've
> found this place.
>
> Thanks and best regards to all who contributed to the thread.
>
> John.

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

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.php


csiph-web