Search code examples
phpcsvfgetcsv

problem with fgetcsv( ) and Unicode


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
}

Solution

  • 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().