bvarvel — 2013-04-02T19:37:54-04:00 — #1
I've got a text file with contents such as this:
A, B, C
D, E, F
G, H, I
I'm trying to figure out a way to read each line into a set of three variables that I can then manipulate.
I found something like this:
$splitcontents = explode($delimiter, $contents);
But this is reading the file like so: A,B,C,D,E,F,G,H,I
When I need to be able to read it as individual rows of three variables.
As a background - this information is scraped from another website and fed into a txt file that is updated once a day. I did it this way to speed up page loads for my visitors.
Can anyone help?
cpradio — 2013-04-02T19:46:34-04:00 — #2
avram — 2013-04-03T09:45:12-04:00 — #3
Either use fgetcsv or load the file with [file() function which will load it in array (each line will be one array) element, then [URL="http://php.net/manual/en/control-structures.foreach.php"]go through the array and [URL="http://php.net/manual/en/function.explode.php"]explode](http://php.net/manual/en/function.file.php)() each item to get CSV values.
kylewolfe — 2013-04-03T14:38:24-04:00 — #4
I did find a bug within this function, that I didn't spend too much time researching.... But I believe depending on the format of the file, possibly even just the extension, fgetcsv will force load the entire file into memory before spooling.
Not a huge deal except for when dealing with 3GB files like I usually am.
kylewolfe — 2013-04-03T14:39:16-04:00 — #5
I'm curious how this is helping performance?