Created
March 11, 2017 13:09
-
-
Save wernersmit/8ad97f554cded0de5ec79db15a34dfb4 to your computer and use it in GitHub Desktop.
Read CSV file and convert to array using fgetcsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Source: http://www.codedevelopr.com/articles/reading-csv-files-into-php-array/ | |
*/ | |
function readCSV($csvFile){ | |
$file_handle = fopen($csvFile, 'r'); | |
while (!feof($file_handle) ) { | |
$line_of_text[] = fgetcsv($file_handle, 1024); | |
} | |
fclose($file_handle); | |
return $line_of_text; | |
} | |
// Set path to CSV file | |
$csvFile = 'test.csv'; | |
$csv = readCSV($csvFile); | |
echo '<pre>'; | |
print_r($csv); | |
echo '</pre>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment