Reputation:
$arr=array();
$row = -1;
if (($handle = fopen("out.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
for ($c = 0; $c < $num; $c++) {
$arr[$row][$c]= $data[$c];
}
}
fclose($handle);
}
I'm using this code to read excel file data, this code counts elements in a row that are divided by comma (,),
Name, Surname, Num, Tel
but in one field I have word Orginal, and this code also divides element by that word like this:
and in that way, I receive wrong elemnts, any help?
Upvotes: 0
Views: 781
Reputation: 57131
In the line
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
the 1000 is the maximum length of data to read, as your data (in the example posted) has more than that, it will split the data.
To allow it to read the data properly you can just leave the second and third parameters as defaults ( null for length - in other words any length and the default delimiter is a comma anyway...
while (($data = fgetcsv($handle)) !== FALSE) {
Upvotes: 1