php - fgetcsv only read first line of csv-file (UPDATE: includes solution) -


i've following code isn't working well. reads first line of csv-file, why? can me? i'm frustrated :(

$handle = fopen($_files['prof_datei']['tmp_name'], "r");  while (($data = fgetcsv($handle, 1000, ",")) !== false) {     $insert_profs_data = $db->prepare("insert professoren (name, titel_prof, titel_dr, titel_ing) values (:eins, :zwei, :drei, :vier)");     $insert_profs_data->bindparam(':eins', $data[0]);     $insert_profs_data->bindparam(':zwei', $data[1]);     $insert_profs_data->bindparam(':drei', $data[2]);     $insert_profs_data->bindparam(':vier', $data[3]);     $insert_profs_data->execute(); }  fclose($handle); 

update solution: if you're working mac execute code, should add following code line before open file:

ini_set('auto_detect_line_endings', true); 

posting answer based on mark baker's , johny's comments.

on mac (os x) , other operating systems use different line endings, may set auto_detect_line_endings true, before reading file.

ini_set('auto_detect_line_endings', true); $contents = file('unknowntype.txt'); 

this should solve issue of php reading first line of file.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -