Can't figure out CSV import
Posted: Wed May 28, 2008 11:42 pm
I'm trying to import a CSV file into a website using php but I can't figure it out...First of all my code... which I got from the php.net website...
The problem is that the whole CSV file is put into the one array instead of breaking each line up into its own array. How do I achieve that?
Code: Select all
$file = 'test.csv';
$fp = fopen($file, 'r');
if (!$fp) {
$err = 1;
}
$length = filesize($file) + 1;
$filecontents = array();
while (($line = fgetcsv($fp, $length, ",")) !== FALSE) {
$filecontents[] = $line;
}
fclose($fp);