FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » reduce all spaces to one
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: reduce all spaces to one [message #176912 is a reply to message #176910] Sun, 05 February 2012 02:15 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: Check email
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 14:36:45 GMT 2024

Total time taken to generate the page: 0.04974 seconds