du8442 2013-06-11 10:27
浏览 43
已采纳

PHP:csv文件编码?

I have a stupid problem. I use a software for export .csv files, and the result is a strange formated text. When I try to deal them in PHP, everything goes wrong.

I copy and paste the text in MS WORD : there is a strange character between each letter.

In php I tried to convert it using utf8_decode/utf8_encode, iconv("ISO-8859-1", "WINDOWS-1252", $str)... in vain.

I guess it's an utf16 encoded text, but I'm not sure of it. I tried some functions to decode utf16, in vain too.

Is someone has a solution to fix this ?

  • 写回答

1条回答 默认 最新

  • duanbu4962 2013-06-11 10:55
    关注

    Your guess it correct:

    file -i NL_JGFR_130326_bac.csv 
    NL_JGFR_130326_bac.csv: text/plain; charset=utf-16le
    

    You can probably use the PHP MultiByte extension to work with UTF-16: http://php.net/manual/en/ref.mbstring.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?