Friday 4 July 2014

PHP Read CSV file and store in array

function fun_readCSV($csvFile) {
    if (!file_exists($csvFile) || !is_readable($csvFile)) {
        fun_logMessage($messageID = '', $message = 'File Not Found', $mstType = 'Developer', $fieldName = '', $rowID = '');
        return FALSE;
    }
    $file_name = basename($csvFile);  // Show File Name
    echo ' File Size '.filesize($csvFile);
    $file_handle = fopen($csvFile, 'r');
    while (!feof($file_handle)) {
        $line_of_text[] = fgetcsv($file_handle, 1024);
    }
    fclose($file_handle);
    $line_of_text = array_unique($line_of_text, SORT_REGULAR);   
    print array2table($line_of_text);
    return $line_of_text;
}

No comments:

Post a Comment