0

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 ?

3
  • What software are you using to export? Can you provide a sample file? Commented Jun 11, 2013 at 10:28
  • I use "Sarbacane" an emailing software. For the sample file, how can we put sample files in Stackoverflow ?? Commented Jun 11, 2013 at 10:32
  • I put the file on a server : lesudtest.com/NL_JGFR_130326_bac.csv . Commented Jun 11, 2013 at 10:40

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. Do you know a function that can convert my file (or string in it) in utf8 for example. I can't find anything like it in the Multibyte String Functions.
It should be as simple as mb_convert_encoding($s, "UTF-16LE", "UTF-8"); although that only produces garbage when I tried it. Maybe "file -i" was not correct or you have mixed encodings?
mb_convert_encoding($s, "UTF-16LE", "UTF-8"); is to encode UTF8 in UTF16. The opposite produces garbage, you're right. I guess I gone deal with these files manually. We can't find a solution every time !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.