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?
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.
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.
I'm curious how this is helping performance?
This topic is now closed. New replies are no longer allowed.