简体   繁体   中英

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.

Use this....

$data[$keyLine][$keyField] = htmlspecialchars_decode(htmlentities(trim( stripslashes( $curField ) ), ENT_IGNORE, "UTF-8", true));

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM