Skip to content
Advertisement

Excel file cannot be read by arrays in php

Sorry for my english) I have a problem! I read file with extension .csv but each line returns string, like this

36794;"""Белоснежка""";"9785783314353";"Белоснежка";0;0;""
36795;"""Гуси-лебеди""";"9785783320361";"Гуси-лебеди";1;0;""

I can’t convert these strings to array. This is my code.

if (($handle = fopen($local_file, "r")) !== FALSE) {
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                $num = count($data);
                $row++;
                for ($c=0; $c < $num; $c++) {
                    echo $data[$c] . "<br />n";
                }
            }
            fclose($handle);
        }

This is my file. enter image description here

Thank you for your help)))

Advertisement

Answer

You ask no question actually…

But the CSV is quoted properly, at least if the double quotes ought to be correct in the columns B and D.

edit: You’re using the wrong delimiter. The file contains semicolon, while you specify colon.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement