Re: [PHP] Parsing CSV files

2007-04-28 Thread Richard Lynch
On Fri, April 27, 2007 5:25 pm, Fernando Cosso wrote:
 One word: explode
 :D

Two Words: Quotes, Commas
:-p

CSV is a nasty nested mess of escapes for escapes from somebody who
clearly did NOT understand how to write a parser/grammar.

Oh, yeah, it came from Microsoft, I think.  That explains everything!

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-28 Thread Edward Vermillion


On Apr 28, 2007, at 2:59 PM, Richard Lynch wrote:


On Fri, April 27, 2007 5:25 pm, Fernando Cosso wrote:

One word: explode
:D


Two Words: Quotes, Commas
:-p



I think I wrote a parser a while back that properly handled commas  
in quotes for csv files. Probably did it the hard way but it worked  
for what I needed it to do, and it required less brain power on my  
part then trying to figure out a regex.


Went through the file a character at a time and ran the strings into  
arrays, ala explode(). Something along the lines of:


$out = array();
$line = 1;
$i = 0;

start of line add chars to $out[$line][$i] (+=) until you get to a  
comma ($i++), keep track of opening and closing quotes and ignore the  
commas in between those, then on to the next line ($line++, $i=0;).



My files were fairly small, so I'm not sure if it would be  
appropriate for large files or busy servers.



Ed

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Eric Butera

On 4/26/07, Edward Kay [EMAIL PROTECTED] wrote:

Todd Cary wrote:
 Is there a function that can parse a comma delimited file into an array?

 Todd

fgetcsv - http://uk.php.net/fgetcsv

Did you even try looking in the manual?

Edward

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



When I searched for csv against on php.net I got redirected to
http://us2.php.net/manual/en/function.gzeof.php.  That isn't exactly
obvious is it?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Tijnema !

On 4/27/07, Eric Butera [EMAIL PROTECTED] wrote:

On 4/26/07, Edward Kay [EMAIL PROTECTED] wrote:
 Todd Cary wrote:
  Is there a function that can parse a comma delimited file into an array?
 
  Todd
 
 fgetcsv - http://uk.php.net/fgetcsv

 Did you even try looking in the manual?

 Edward

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


When I searched for csv against on php.net I got redirected to
http://us2.php.net/manual/en/function.gzeof.php.  That isn't exactly
obvious is it?
.


It seems that some mirrors do that (us2, us3, nl3) but others don't
(nl2,fr2,ar2,fr3)
Aren't they keeping the same pages?

Tijnema

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Parsing CSV files

2007-04-27 Thread Edward Kay

 When I searched for csv against on php.net I got redirected to
 http://us2.php.net/manual/en/function.gzeof.php.  That isn't exactly
 obvious is it?
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

OK, sorry for being critical. As Tijnema showed, the different mirrors seem to 
be giving different search results. Searching for 'csv' on http://uk.php.net 
goes to http://uk.php.net/manual-lookup.php?pattern=csv which clearly lists the 
suitable functions.

It looks as if some of the mirrors are a bit dirty :)

Edward

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Tijnema !

On 4/27/07, Edward Kay [EMAIL PROTECTED] wrote:


 When I searched for csv against on php.net I got redirected to
 http://us2.php.net/manual/en/function.gzeof.php.  That isn't exactly
 obvious is it?

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


OK, sorry for being critical. As Tijnema showed, the different mirrors seem to 
be giving different search results. Searching for 'csv' on http://uk.php.net 
goes to http://uk.php.net/manual-lookup.php?pattern=csv which clearly lists the 
suitable functions.

It looks as if some of the mirrors are a bit dirty :)

Edward



Some... It looks like it more then half of the mirrors. Seems a small
bug in the site, bug report?

Tijnema

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Eric Butera

On 4/27/07, Edward Kay [EMAIL PROTECTED] wrote:


 When I searched for csv against on php.net I got redirected to
 http://us2.php.net/manual/en/function.gzeof.php.  That isn't exactly
 obvious is it?

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


OK, sorry for being critical. As Tijnema showed, the different mirrors seem to 
be giving different search results. Searching for 'csv' on http://uk.php.net 
goes to http://uk.php.net/manual-lookup.php?pattern=csv which clearly lists the 
suitable functions.

It looks as if some of the mirrors are a bit dirty :)

Edward




I checked the UK mirror before I posted and noted it went to the
correct function.  I just wanted to state for anybody looking at this
that sometimes people can actually be trying to find out what it is
and aren't going to get any help from the site and need a little
nudge.  Granted some people might not try hard enough but still it is
worth considering.  =)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Daniel Brown

   Maybe the PHP site itself should be Wiki-fied so that we could just go
in ourselves and fix the errors.  I don't see that happening any time soon
though


On 4/27/07, Eric Butera [EMAIL PROTECTED] wrote:


On 4/27/07, Edward Kay [EMAIL PROTECTED] wrote:

  When I searched for csv against on php.net I got redirected to
  http://us2.php.net/manual/en/function.gzeof.php.  That isn't exactly
  obvious is it?
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 

 OK, sorry for being critical. As Tijnema showed, the different mirrors
seem to be giving different search results. Searching for 'csv' on
http://uk.php.net goes to http://uk.php.net/manual-lookup.php?pattern=csvwhich 
clearly lists the suitable functions.

 It looks as if some of the mirrors are a bit dirty :)

 Edward



I checked the UK mirror before I posted and noted it went to the
correct function.  I just wanted to state for anybody looking at this
that sometimes people can actually be trying to find out what it is
and aren't going to get any help from the site and need a little
nudge.  Granted some people might not try hard enough but still it is
worth considering.  =)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107


Re: [PHP] Parsing CSV files

2007-04-27 Thread Stut

Daniel Brown wrote:

   Maybe the PHP site itself should be Wiki-fied so that we could just go
in ourselves and fix the errors.  I don't see that happening any time soon
though


There's nothing stopping you submitting patches to the documentation 
mailing list. As far as I know they welcome decent patches with open 
arms. A wiki would (IMHO) lead to a general and rapid degradation in the 
quality of the documentation.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Daniel Brown

   Yeah, that's why I followed-up with saying, I don't see that happening
any time soon though

   Not only would you have unqualified people putting in bad (though not
intentionally wrong) information, there would always be the presence of
vandalism, as on any other Wiki.  The serious problem here, though, is that
it's a programming language, so severe havoc could definitely be wreaked.

On 4/27/07, Stut [EMAIL PROTECTED] wrote:


Daniel Brown wrote:
Maybe the PHP site itself should be Wiki-fied so that we could just
go
 in ourselves and fix the errors.  I don't see that happening any time
soon
 though

There's nothing stopping you submitting patches to the documentation
mailing list. As far as I know they welcome decent patches with open
arms. A wiki would (IMHO) lead to a general and rapid degradation in the
quality of the documentation.

-Stut





--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107


Re: [PHP] Parsing CSV files

2007-04-27 Thread Tijnema !

On 4/27/07, Stut [EMAIL PROTECTED] wrote:

Daniel Brown wrote:
Maybe the PHP site itself should be Wiki-fied so that we could just go
 in ourselves and fix the errors.  I don't see that happening any time soon
 though

There's nothing stopping you submitting patches to the documentation
mailing list. As far as I know they welcome decent patches with open
arms. A wiki would (IMHO) lead to a general and rapid degradation in the
quality of the documentation.

-Stut


If you can point me where to find the documentation on the CVS server,
i might write a patch :)

Tijnema

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Stut

Tijnema ! wrote:

On 4/27/07, Stut [EMAIL PROTECTED] wrote:

Daniel Brown wrote:
Maybe the PHP site itself should be Wiki-fied so that we could 
just go
 in ourselves and fix the errors.  I don't see that happening any 
time soon

 though

There's nothing stopping you submitting patches to the documentation
mailing list. As far as I know they welcome decent patches with open
arms. A wiki would (IMHO) lead to a general and rapid degradation in the
quality of the documentation.

-Stut


If you can point me where to find the documentation on the CVS server,
i might write a patch :)


http://doc.php.net/php/dochowto/

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Tijnema !

On 4/27/07, Stut [EMAIL PROTECTED] wrote:

Tijnema ! wrote:
 On 4/27/07, Stut [EMAIL PROTECTED] wrote:
 Daniel Brown wrote:
 Maybe the PHP site itself should be Wiki-fied so that we could
 just go
  in ourselves and fix the errors.  I don't see that happening any
 time soon
  though

 There's nothing stopping you submitting patches to the documentation
 mailing list. As far as I know they welcome decent patches with open
 arms. A wiki would (IMHO) lead to a general and rapid degradation in the
 quality of the documentation.

 -Stut

 If you can point me where to find the documentation on the CVS server,
 i might write a patch :)

http://doc.php.net/php/dochowto/

-Stut


Whoops, didn't realise the doc system was so huge :) I thought it was
just a few (1000 max) lines

But well, it's a lot more, so somebody with a little bit more
experience could better do it :)

Tijnema




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Stut

Tijnema ! wrote:

On 4/27/07, Stut [EMAIL PROTECTED] wrote:

Tijnema ! wrote:
 On 4/27/07, Stut [EMAIL PROTECTED] wrote:
 Daniel Brown wrote:
 Maybe the PHP site itself should be Wiki-fied so that we could
 just go
  in ourselves and fix the errors.  I don't see that happening any
 time soon
  though

 There's nothing stopping you submitting patches to the documentation
 mailing list. As far as I know they welcome decent patches with open
 arms. A wiki would (IMHO) lead to a general and rapid degradation 
in the

 quality of the documentation.

 -Stut

 If you can point me where to find the documentation on the CVS server,
 i might write a patch :)

http://doc.php.net/php/dochowto/

-Stut


Whoops, didn't realise the doc system was so huge :) I thought it was
just a few (1000 max) lines

But well, it's a lot more, so somebody with a little bit more
experience could better do it :)


Note that you don't have to create a patch file. If you want to 
contribute to the documentation, join that mailing list and start 
submitting changes. If you do it often enough I'm sure they'll manage to 
convince you that setting yourself up to submit patch files is worthwhile.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Tijnema !

On 4/27/07, Stut [EMAIL PROTECTED] wrote:

Tijnema ! wrote:
 On 4/27/07, Stut [EMAIL PROTECTED] wrote:
 Tijnema ! wrote:
  On 4/27/07, Stut [EMAIL PROTECTED] wrote:
  Daniel Brown wrote:
  Maybe the PHP site itself should be Wiki-fied so that we could
  just go
   in ourselves and fix the errors.  I don't see that happening any
  time soon
   though
 
  There's nothing stopping you submitting patches to the documentation
  mailing list. As far as I know they welcome decent patches with open
  arms. A wiki would (IMHO) lead to a general and rapid degradation
 in the
  quality of the documentation.
 
  -Stut
 
  If you can point me where to find the documentation on the CVS server,
  i might write a patch :)

 http://doc.php.net/php/dochowto/

 -Stut

 Whoops, didn't realise the doc system was so huge :) I thought it was
 just a few (1000 max) lines

 But well, it's a lot more, so somebody with a little bit more
 experience could better do it :)

Note that you don't have to create a patch file. If you want to
contribute to the documentation, join that mailing list and start
submitting changes. If you do it often enough I'm sure they'll manage to
convince you that setting yourself up to submit patch files is worthwhile.

-Stut


There are more interesting things to do than updating documentation ;)

I was wanting to extend the CURLOPT_ constants, but it seemed that
nobody had interest in that, so i didn't ...

Tijnema

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Richard Lynch
On Thu, April 26, 2007 3:39 pm, Todd Cary wrote:
 Is there a function that can parse a comma delimited file into an
 array?

fgetcsv should work...



-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Richard Lynch
On Fri, April 27, 2007 9:45 am, Daniel Brown wrote:
 Maybe the PHP site itself should be Wiki-fied so that we could
 just go
 in ourselves and fix the errors.  I don't see that happening any time
 soon
 though

Gah.

php.net as a Wikki would be a nightmare...

If you *really* want to fix the errors, grab the docs source from CVS
and start figuring out what needs doing and submit patches.

The function lookup routine has a whole mess of special case
hard-coded lookups that happen before the usual exact match on a
function name lookup.

I dunno why some of those do the things they do, but if you get a
weird re-direct (like CSV - gzeof) then using the search box in the
navbar with online documentation instead of function list will
almost always get you what you really wanted.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Richard Lynch
On Fri, April 27, 2007 1:58 pm, Tijnema ! wrote:
 There are more interesting things to do than updating documentation ;)

 I was wanting to extend the CURLOPT_ constants, but it seemed that
 nobody had interest in that, so i didn't ...

I believe the issue here is that having the constants with no body of
code to do something useful when the constants would just be
counter-productive...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Tijnema !

On 4/27/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Fri, April 27, 2007 1:58 pm, Tijnema ! wrote:
 There are more interesting things to do than updating documentation ;)

 I was wanting to extend the CURLOPT_ constants, but it seemed that
 nobody had interest in that, so i didn't ...

I believe the issue here is that having the constants with no body of
code to do something useful when the constants would just be
counter-productive...


Well, actually it was quite simple, adding the constants and adding
them to the function that passes it to the curl library and it would
work. So it has some extra functionality. So, you might never use
them, but somebody else might.

Tijnema


--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Richard Lynch
On Fri, April 27, 2007 2:44 pm, Tijnema ! wrote:
 On 4/27/07, Richard Lynch [EMAIL PROTECTED] wrote:
 On Fri, April 27, 2007 1:58 pm, Tijnema ! wrote:
  There are more interesting things to do than updating
 documentation ;)
 
  I was wanting to extend the CURLOPT_ constants, but it seemed that
  nobody had interest in that, so i didn't ...

 I believe the issue here is that having the constants with no body
 of
 code to do something useful when the constants would just be
 counter-productive...

 Well, actually it was quite simple, adding the constants and adding
 them to the function that passes it to the curl library and it would
 work. So it has some extra functionality. So, you might never use
 them, but somebody else might.

In that case, if you submit a patch, it will almost-for-sure go in.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-27 Thread Todd Cary
Many thanks!  I must be losing my eyesight!  There it is and it works as 
expected...great.


Todd

Richard Lynch wrote:

On Thu, April 26, 2007 3:39 pm, Todd Cary wrote:
  

Is there a function that can parse a comma delimited file into an
array?



fgetcsv should work...



  


--
Ariste Software
2200 D Street Ext
Petaluma, CA 94952
(707) 773-4523



[PHP] Parsing CSV files

2007-04-26 Thread Todd Cary
Is there a function that can parse a comma delimited file into an 
array?


Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-26 Thread Richard Davey

Todd Cary wrote:


Is there a function that can parse a comma delimited file into an array?


http://uk.php.net/manual/en/function.str-getcsv.php

Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-26 Thread Brad Bonkoski

Todd Cary wrote:

Is there a function that can parse a comma delimited file into an array?

Todd


http://us.php.net/manual/en/function.fgetcsv.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Parsing CSV files

2007-04-26 Thread Edward Kay

Todd Cary wrote:

Is there a function that can parse a comma delimited file into an array?

Todd


fgetcsv - http://uk.php.net/fgetcsv

Did you even try looking in the manual?

Edward

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php