Page 1 of 1

fgetcsv() not working with special chars!

Posted: Tue Feb 15, 2011 2:19 pm
by mjsw
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:

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);
It displays:
1 ASCII Błąd w zapytaniu podczas usuwania obrazków: {0} UTF-8
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?

Re: fgetcsv() not working with special chars!

Posted: Tue Feb 15, 2011 3:11 pm
by AbraCadaver
You're positive that your outputted page has this:

[text]<meta http-equiv="content-type" content="text/html; charset=UTF-8" />[/text]

Re: fgetcsv() not working with special chars!

Posted: Tue Feb 15, 2011 3:17 pm
by mjsw
AbraCadaver wrote:You're positive that your outputted page has this:

[text]<meta http-equiv="content-type" content="text/html; charset=UTF-8" />[/text]
yes, it's there. there is no problem with page or file encoding in my case, everything is UTF-8. Problem is with this function...