I'm trying to convert a string with unknown charset to UTF-8. I tried all kind of solutions, but everything I try fails. I the code in the answer of this question: PHP: Convert any string to UTF-8 without knowing the original character set, or at least try. This works like a charm on my local vagrant installation. But on my production server, this fail.
The convert code:
iconv(mb_detect_encoding($text, mb_detect_order(), true), "UTF-8", $text);
The string to convert: De Krön 2
The error:
iconv(): Detected an illegal character
iconv('', 'UTF-8', 'De Kr\xC3\xB6n 2')
As you can see, the ö
is a encoded like \xC3\Xb6
. I have read that this might be an issue with copy pasting from MS Word. However, I don't have this in my control. I get a CSV file and need to import this in a database.
Like I said, it is working local on my vagrant (Homestead) installation, but not on my production server. What could cause this issue?