Converting CSV file to UCS-2LE encoding with php -
i'm creating csv file. need in ucs-2le encoding. tried following, neither of work:
$value = mb_convert_encoding($value,"ucs-2le");
$value= iconv( mb_detect_encoding( $value ), 'ucs-2le', $value );
opening file in notepad++ shows encoding ansi.
code:
$file = fopen($filename,"w"); array_walk($csv_data, 'encodecsv'); foreach ($csv_data $line) { fputcsv($file, explode(',', $line)); } fclose($file); function encodecsv(&$value, $key){ $value = mb_convert_encoding($value,"ucs-2le"); //$value= iconv( mb_detect_encoding( $value ), 'ucs-2le', $value ); }
you should add byte-order-mark (bom) @ beginning of file. should '\xff\xfe' in case:
$file = fopen($filename,"w"); fwrite($file, '\xff\xfe');
Comments
Post a Comment