tessguefen
8/12/2015 - 10:29 PM

Loop through CSV with PHP Example

Loop through CSV with PHP Example

<?PHP
function readCSV($csvFile){
	$file_handle = fopen($csvFile, 'r');
	while (!feof($file_handle) ) {
		$line_of_text[] = fgetcsv($file_handle, 0);
	}
	fclose($file_handle);
	return $line_of_text;
}
 
$csv = readCSV('YOURCSVFILEHERE.csv'); // Make sure this exsists or you will have a forever error log.
foreach ( $csv as $c ) {
    $firstColumn = $c[0];
    $secondColumn = $c[1];
    $thirdColumn = $c[3];  
}
?>