Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reduce all spaces to one

11 views
Skip to first unread message

John

unread,
Feb 3, 2012, 2:03:29 PM2/3/12
to
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.


Jerry Stuckle

unread,
Feb 3, 2012, 2:36:46 PM2/3/12
to
Try

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


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

crankypuss

unread,
Feb 3, 2012, 3:05:59 PM2/3/12
to
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);

Jerry Stuckle

unread,
Feb 3, 2012, 3:17:13 PM2/3/12
to
Doesn't work - try it with 'abc def ghi jkl'.

M. Strobel

unread,
Feb 3, 2012, 3:19:39 PM2/3/12
to
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.

M. Strobel

unread,
Feb 3, 2012, 3:30:47 PM2/3/12
to
Interactive test:

php > echo ereg_replace('[ ]+', ' ', 'here are some spaces ');
here are some spaces
php >

It works just fine, unfortunately these functions are marked deprecated. I find the
PCRE escape sequences hard to read.

/Str.

John

unread,
Feb 3, 2012, 3:59:03 PM2/3/12
to
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 !!

Thomas 'PointedEars' Lahn

unread,
Feb 4, 2012, 9:41:33 AM2/4/12
to
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

Jerry Stuckle

unread,
Feb 4, 2012, 9:57:43 AM2/4/12
to
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.

Thomas 'PointedEars' Lahn

unread,
Feb 4, 2012, 10:05:49 AM2/4/12
to
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

Thomas 'PointedEars' Lahn

unread,
Feb 4, 2012, 10:21:20 AM2/4/12
to
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

Jerry Stuckle

unread,
Feb 4, 2012, 4:00:52 PM2/4/12
to
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.

John

unread,
Feb 4, 2012, 4:26:44 PM2/4/12
to
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.

Thomas 'PointedEars' Lahn

unread,
Feb 4, 2012, 6:05:07 PM2/4/12
to
John wrote:

> Am 04.02.2012 15:41, 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.

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

John

unread,
Feb 4, 2012, 7:39:57 PM2/4/12
to
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.

Jerry Stuckle

unread,
Feb 4, 2012, 8:56:04 PM2/4/12
to
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.

Thomas 'PointedEars' Lahn

unread,
Feb 4, 2012, 9:15:22 PM2/4/12
to
John wrote:

> Am 05.02.2012 00:05, schrieb Thomas 'PointedEars' Lahn:
>> $words = str_split(' ', preg_replace('/\\s+/', ' ', $text));

That is _not_ what I *recommended*. Please learn to quote.

> I have the problem of 'filtering' a text file, exported from Excel as a
> 'Windows text file with <return>', containing <tabs> between numbers.

Sounds like a CSV file, having <HT> as field delimiter and <CR><LF> as
record delimiter. Right?

> 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 this is a CSV file and the fields contain a number each, not words, then
I do not see how additional splitting at /\s+/ would help. The fields
should not contain white-space as they contain only one number each and are
delimited by white-space, in particular <HT> ("\t").

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

Do you know <http://php.net/fgetcsv>?

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

You are welcome. (But there should be no space before the `!' in English or
German.)


PointedEars

Doug Miller

unread,
Feb 4, 2012, 11:02:42 PM2/4/12
to
John <john_tak...@agdp.de> wrote in
news:jgkj4t$j9l$1...@speranza.aioe.org:

> 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 :-))

Your English is more than adequate. [*] However, PointedHead's often is not. English is not his first
language; as far as I know, German is. And he doesn't understand English, or express himself
thereby, as well as he thinks he does. If you are a native speaker of German, you would assuredly
communicate more clearly with him, and he with you, in your native tongue.

[*] In fact, it's excellent. I'm a native speaker of American English, I've been following this thread
since the beginning, and I had no inkling before today that you might not be a native speaker also.

Thomas 'PointedEars' Lahn

unread,
Feb 4, 2012, 11:35:56 PM2/4/12
to
Doug Miller wrote:
If you cannot find anything wrong with phrases like "the 'regex' solutions
fits perfectly", then you must be bli^Wborn Northern American. Such people
− unless they have studied English literature – are not really qualified to
make a proper assessment of what is or is not proper English. *Ain't* it
so, *bro*? You would be well-advised to learn your own language instead of
misleading people into believing that they are "excellent" at it.

Then again, you are only an address-munging troll who has not contributed a
single line of on-topic content to this newsgroup *at least* within the last
two months, so nobody sane here should really care what you think.

Speaking of which, the OP is an address munger too, so unfortunately he must
join you in my killfile.

<http://www.interhack.net/pubs/munging-harmful/>


F'up2 poster

PointedEars
--
Sometimes, what you learn is wrong. If those wrong ideas are close to the
root of the knowledge tree you build on a particular subject, pruning the
bad branches can sometimes cause the whole tree to collapse.
-- Mike Duffy in cljs, <news:Xns9FB6521286...@94.75.214.39>

Gregor Kofler

unread,
Feb 5, 2012, 5:03:39 AM2/5/12
to
Am 2012-02-05 05:02, Doug Miller meinte:
I'm not a native speaker (and do have my fair share of grammar and
spelling mistakes in my postings, too), but the original posting

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

sounds a bit Yodaish to me - it's easy to understand but not what I'd
expect from a *native* speaker.

Gregor

The Natural Philosopher

unread,
Feb 5, 2012, 5:11:16 AM2/5/12
to
just lacks punctuation.


e.i. "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)) ???"


But you are right: its slightly Germanic in the word order, ..one might
say more likely "reduce all the spaces between words, to one."

But that is something, up with which one can easily put...;-)

Thomas 'PointedEars' Lahn

unread,
Feb 5, 2012, 8:00:26 AM2/5/12
to
Gregor Kofler wrote:

> I'm not a native speaker […], but the original posting
> […]
> sounds a bit Yodaish to me - […]
^^^^^^^
*g* I have to remember that one.


Regards,
--
(F'up2) PointedEars

The Natural Philosopher

unread,
Feb 5, 2012, 8:53:41 AM2/5/12
to
Thomas 'PointedEars' Lahn wrote:
> Gregor Kofler wrote:
>
>> I'm not a native speaker […], but the original posting
>> […]
>> sounds a bit Yodaish to me - […]
> ^^^^^^^
> *g* I have to remember that one.
>
>
It's a classic - the Germanic construction is to put the verb at the
end, you may get the English words right, but the ordering of them is,
to a normal English speakers ear, a bit of a give-away.

The device is often used in drama to give an impression of foreign-ness.

As in

"The ordering of words, most important, is".

> Regards,

John

unread,
Feb 5, 2012, 12:02:24 PM2/5/12
to
Am 05.02.2012 02:56, schrieb Jerry Stuckle:

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

I thought about that, but I am still left with the problem of some sort
of manual intervention : for example the literals are not embedded in
quotes. I'll have to differentiate between columns/rrow titles and
actual values.

Also the problem with the commas vs points is due to regional
configuration, (in the EU decimal values have mostly commas).

John

unread,
Feb 5, 2012, 12:04:21 PM2/5/12
to
Am 05.02.2012 03:15, schrieb Thomas 'PointedEars' Lahn:


> Sounds like a CSV file, having<HT> as field delimiter and<CR><LF> as
> record delimiter. Right?
>

not quite : the regional configuration uses commas instead of points
for decimal values

John

unread,
Feb 5, 2012, 12:05:52 PM2/5/12
to
Am 05.02.2012 05:02, schrieb Doug Miller:
> John<john_tak...@agdp.de> wrote in

> Your English is more than adequate. [*]
> [*] In fact, it's excellent.

Thanks to my irish wife... I'm italian actually...:-)))

Michael Fesser

unread,
Feb 5, 2012, 3:47:20 PM2/5/12
to
.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

Jerry Stuckle

unread,
Feb 5, 2012, 4:12:01 PM2/5/12
to
That's all we need - another troll in this newsgroup.

M. Strobel

unread,
Feb 5, 2012, 4:23:59 PM2/5/12
to
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.

The Natural Philosopher

unread,
Feb 5, 2012, 4:37:59 PM2/5/12
to
:-)

Michael Fesser

unread,
Feb 5, 2012, 5:34:53 PM2/5/12
to
.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

Doug Miller

unread,
Feb 5, 2012, 8:31:44 PM2/5/12
to
While his English is not perfect, it's better than that of a good many native speakers. And he seems to
understand it quite a bit better than you do.

My comment stands: you neither write nor understand English as well as you think you do.

Now go back to trolling the Javascript newsgroups.

M. Strobel

unread,
Feb 6, 2012, 3:31:40 AM2/6/12
to
Don't be so baaad. He will choke on "Javascript".

/Str.

0 new messages