fgetcsv looks interesting. What I still don't understand is whether or not fread() delimits the .csv file with newlines. Here's a simplified version of the .csv file:
name, address, hatsize
name, address, hatsize
//I point to, open, and read the file
$path = 'comma_delimited.csv';
$data = fopen($path, "r");
$contents = fread($data, filesize($path));
fclose($data);
//Here's where I have problems
//I've been assuming that fread()
//places newline characters at the
//end of lines
$one_line = strtok($contents, "\n");
while($one_line !== false){
echo "Line is " . $one_line . "<br />";
$one_line = strtok("\n");
}
The echo command outputs the entire file instead of the one line I expected to get from strtok("\n"):
name, address, hatsizename, address, hatsize
instead of:
name, address, hatsize
I need a way of iterating through the flatfile so that I get one line at a time. If fread() really doesn't place newline characters at the end of lines, how can I keep the lines separate, especially since I don't know exactly how long a particular line will be?