fgetcsv() not working with special chars!
Posted: Tue Feb 15, 2011 2:19 pm
Hello,
I'm trying to perform simple operation in php, this is reading a csv file and displaying it on page. I've read the manual and everything, but php seems to be bugged as I can't get it to work properly with special characters (like accent chars in polish or any other language). CSV file has UTF8 encoding, page is also using UTF8. Here is the code:
It displays:
I'm trying to perform simple operation in php, this is reading a csv file and displaying it on page. I've read the manual and everything, but php seems to be bugged as I can't get it to work properly with special characters (like accent chars in polish or any other language). CSV file has UTF8 encoding, page is also using UTF8. Here is the code:
Code: Select all
setlocale(LC_ALL, 'pl-PL.UTF-8');
if(($handle=fopen('file.csv',"r"))!==FALSE)
{
echo "<table>";
while(($data=fgetcsv($handle,0,"\t","\""))!==FALSE)
{
$num=count($data);
echo "<tr>\n";
$row++;
for($c=0;$c<$num;$c++)
{
echo "<td>".$data[$c].' '.mb_detect_encoding($data[$c])."</td>\n";
}
echo "</tr>\n";
}
echo "</table>";
}
fclose($handle);instead of:1 ASCII Błąd w zapytaniu podczas usuwania obrazków: {0} UTF-8
I have also tried using iconv and utf8_encode on the displayed data, with no luck. What is wrong here?1 ASCII Błąd w zapytaniu podczas usuwania obrazków: {0} UTF-8