I have a CSV file and I want to parse it using PHP:
Access_Code,Home_Address, Work_Address
1, 100 Broad St, 100 Main St
2, 200 Broad St, 200 Main St
3, 300 Broad St, 300 Main St
Here is my code:
$file = fopen($target_path,"r");
while(!feof($file))
{
$groups2 = fgetcsv($file,",");
print_r($groups2);
}
fclose($file);
I don't want anything fancy, just to figure out why this happens:
OUTPUT:
Array ( [0] => Access_Code [1] => Work_Address [2] => Home_Address 1 [3] => 100 Broad St [4] => 100 Main St 2 [5] => 200 Broad St [6] => 200 Main St 3 [7] => 300 Broad St [8] => 300 Main St )
I should have an array with 12 objects, no? Why is my first column being swallowed up by the third (i.e. Home_Address 1, 200 Main St 3, etc.)?
Thanks!!
\rinstead of\n?), find out what it is, and maybe useauto_detect_line_endings