0

I know this is going to be super simple when someone shows me but I can't seem to work it out. I'm trying to read in a csv file like the below and then pass it to a function called 'row'. The CSV has 4 columns, I want to read in a row and then split the data on a ',' and put it into the line $this->Row(array('','','','')); where I then want to move onto the next line, until I've finished all lines, does anyone have any ideas?

1,1,1,1

2,2,2,2

3,3,3,3

function LoadData($file)
{
    $lines = file($file);
    $data = array();   
    foreach($lines as $line){
        $data[] = explode(',',trim($line));
        $this->Row(array('','','',''));
    } 
}
James
  • 474
  • 4
  • 9
  • 22

1 Answers1

0

Try this :

<?php

    function getCsv($file) {
        if (($handle = fopen($file, "r")) !== FALSE) {

            while ( ( $data = fgetcsv( $handle, 100, ',' ) ) !== FALSE ) {
                $this->Row($data);
            }

            fclose($handle);
        }
    }

    getCsv('/path/to/file.csv');

?>
ncrocfer
  • 2,542
  • 4
  • 33
  • 38