Why double quotes is automatically added to the first cell on CSV Import?

82 Views Asked by At

I'm trying to do a CSV(which is generated by a third party) import,in PHP and I've the following fields in the CSV.

ID, Size1, Size2, OneOrTwo, Min, Max

But on Import I'm getting an array as following

Array
(
    [0] => "ID"
    [1] => Size1
    [2] => Size2
    [3] => OneOrTwo
    [4] => Min
    [5] => Max
)

I'm getting an output with quote added to the first field name, ie ID turns to "ID". If I edit the cell value and re-type the field name and save again, the issue seems to be disappearing. I'm not sure why it happens. It would be of great help if somebody could help me in solving out the problem.

This is the code for import.

$currentcsv  = fopen('/data.csv', "r");
    $csvArray  = array();
    while (!feof($currentcsv)) {
        $data = fgetcsv($currentcsv);
        if (!empty($data)) {
            $csvArray[] = $data;
        }
    }
echo "<pre>";
die(print_r($csvArray[0]));
0

There are 0 best solutions below