Can't archive to proper encode csv in PHP -


i have function import csv.

public function csv_to_array($filename, $delimiter = ',', $enclosure = '"') {      $header = null;     $data = array();       if (($handle = fopen($filename, 'r')) !== false)     {          $all = 0;          while(($row = fgetcsv($handle, 0, $delimiter, $enclosure)) !== false)         {              $i=0;             foreach($row $string) {                 $row[$i] = utf8_encode($string);                 $i++;             }              if(!$header) {                 $header = $row;             }else{                 $data[] = array_combine($header, $row);             }             $all++;         }          fclose($handle);      }      return $data; } 

some files, come in ansi encoding don't work str_getcsv or fgetcsv. tried convert them first

mb_convert_encoding($line, 'windows-1252', 'utf-8'); 

or iconv, utf8_encode, ...

in other projects never stumbled issue. of above trick, not time. whole system , database set utf-8. there known work around, how solve problem? i'm helpless :(

you aren't using of encoding functions right. if want convert from windows-1252 utf-8 neither of these work:

 utf8_encode($string) 

... converts from iso-8859-1 utf-8 (reference).

mb_convert_encoding($line, 'windows-1252', 'utf-8'); 

... converts from utf-8 windows-1252 (reference).

when you're in hurry read docs ;-)


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -