Re: reduce all spaces to one [message #176912 is a reply to message #176910] |
Sun, 05 February 2012 02:15 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
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
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
|
|
|