file = fopen($filename, 'r'); } function &getTransaction() { $data = fgetcsv($this->file, 1000, ","); if($data === false) { $answer = false; return $answer; } if(!empty($data[0])) { //get account details, then get the next transaction. $this->readAccount($data); return $this->getTransaction(); } if(empty($data[1]) || $data[1] == 'Posted Date') { //skip empty rows return $this->getTransaction(); } $answer['store'] = $data[2]; $i = 3; while(!is_numeric($data[$i]))//sometimes the store has a comma in the name. that's dumb, because they don't quote the fields, but oh well. $i++; $answer['amount'] = $data[$i]; $answer['unique_id'] = $data[$i+3]; $i = 8; $transactionCodes = array('618', '751', '631', '222', '219', '221', '352', '633', '890', '450', '610'); while(!in_array($data[$i], $transactionCodes) && $i < 11)//same as above... $i++; $answer['date'] = $data[$i + 5]; $answer['entered_by'] = $this->enteredBy; if($data[$i + 4] == 'Credit') $answer['amount'] = '-' . $answer['amount']; return $answer; } function readAccount($data) { $this->accountType = $data[0]; $this->enteredBy = $data[1]; $this->account = $data[2]; $this->balance = $data[4]; $this->routing = $data[6]; } }