problem with fgetcsv( ) and Unicode

user006779 picture user006779 · May 28, 2011 · Viewed 11k times · Source

i have a code. on localhost i have not problem with reading csv file (with Unicode chars). but when upload code on host output is nothing. why? what is solution?

while (($data=fgetcsv($fin,5000,","))!==FALSE) 
{
 var_dump($data[0]);  //on host output is `string(0) ""` but on local i can see output
 var_dump($data[1]);  //$data[1] is integer and  i can see output
}

Answer

timdream picture timdream · May 28, 2011

Note:

Locale setting is taken into account by this function. If LANG is e.g. en_US.UTF-8, files in one-byte encoding are read wrong by this function.

http://php.net/fgetcsv

One possible solution is to use setlocale().