<?php
$row = 1;
$handle = fopen ("test.csv","r");
while ($data = fgetcsv ($handle, 1000, ",")) {
$num = count ($data);
print "<p> $num fields in line $row: <br>\n";
$row++;
for ($c=0; $c < $num; $c++) {
print $data[$c] . "<br>\n";
}
}
fclose ($handle);
?>
The above comes from php manual,but I didn't see where to specify the encoding(like utf8 or so)
Try to change the locale.
Like it says below the example in the manual you gave:
Suggested approach by comment on the same page:
From
setlocale()
:try this:
One such thing is the occurrence of the UTF byte order mark, or BOM. The UTF-8 character for the byte order mark is U+FEFF, or rather three bytes – 0xef, 0xbb and 0xbf – that sits in the beginning of the text file. For UTF-16 it is used to indicate the byte order. For UTF-8 it is not really necessary.
So you need to detect the three bytes and remove the BOM. Below is a simplified example on how to detect and remove the three bytes.
That's all