Search code examples
phpcharacter-encodingutf8-decode

PHP: How to convert special composed character from UTF-8 to Latin 3


I am trying to export data from my database (UTF-8) to CSV wich is to be opened on MS Excel (Latin 3). For that I am using

$data[$keyLine][$keyField] = utf8_decode(html_entity_decode($curField, ENT_QUOTES, "UTF-8"));

The problem is that my data is in french, and includes words such as cœur. All data exported is looking fine except that composed character œ, where I am getting a question mark (cœur is converted to c?ur), how can I fix this?

Thanks in advance.


Solution

  • Thanks to @RiggsFolly 's tip, I managed to do it with iconv

    $data[$keyLine][$keyField] = iconv("UTF-8", "Windows-1252", html_entity_decode($curField, ENT_QUOTES, "UTF-8"));
    

    Windows-1252 was the only charset that worked, thou. Neither ISO-8859-15 or 16 worked for me.