Skip to content

php SplFileObject and the difference between fgetcsv and current

I had to investigate a bug and figured out a strange behavior in the SplFileObject implementation of php. I know, some of you would add "again", but this does not matter.
To illustrate this problem, I created a little example file. If you run it, you get the following output:


generating content.
..........
writing content.
..........
using fgetcsv and writing key 13 times.
0 0 1 2 3 4 5 6 7 8 9 10 10 
using current and writing key 13 times.
0 0 0 0 0 0 0 0 0 0 0 0 0

As you can see, if you use "fgetcsv", the current key is move to the next step.
If you use "current", the current key won't get updated (which is most likely what you want).
You can easily set the csv delimiter etc. by using setCsvControl()".

Categories: coding
Defined tags for this entry: , , , , , ,
Vote for articles fresher than 7 days!
Derzeitige Beurteilung: 4.50 of 5, 2 Stimme(n) 971 hits