Okay, I've spent several hours on this problem and I'm not sure what's going on. I think I just need a fresh perspective on this problem especially since I've been up for over 24 hours and the deadline for this is in five hours.
I am getting an Undefined offset notice for every single offset (0 to 907) when I try to use the data I pulled from a CSV. (It probably means I am not successfully pulling the data, but I am exhausted and would appreciate some help)
Does anyone know what I'm doing wrong?
$lines = array();
$lines2 = "";
$one = array();
$two = array();
$three = array();
$four = array();
$five = array();
$six = array();
$header = "";
$footer = "";
$countLines = 0;
/*
* Open the file and store its data into an array
*/
$fp = fopen('db.csv','r') or die("can't open file");
while($lines = fgetcsv($fp)) {
for ($k = 0, $m = count($lines) - 1; $k < $m; $k++) {
$one[$k] = $lines[0];
$two[$k] = $lines[1];
$three[$k] = $lines[2];
$four[$k] = $lines[3];
$five[$k] = $lines[4];
$six[$k] = $lines[5];
}
$countLines++;
}
fclose($fp) or die("can't close file");
/*
* Set up file header
*/
$header = "Header"
;
/*
* Set up file footer
*/
$footer = "Footer";
/*
* Prepare data for export
*/
for ($i = 0, $j = $countLines - 1; $i < $j; $i++) {
$lines2 .= $one[$i] ." ".
$two[$i] ." ".
str_pad($three[$i], 3) ." ".
str_pad($four[$i], 30) ." ".
str_pad($five[$i], 30) ." ".
str_pad($six[$i], 30) ."\r\n";
}
/*
* Store data in file
*/
$fp = fopen('db2.csv', 'w') or die("can't open file");
fwrite($fp, $header);
fwrite($fp, $lines2);
fwrite($fp, $footer);
fclose($fp) or die("can't close file");
The CSV file is a standard comma-delimited file so I don't see any reason to post that data here.