0

Why this line of code:

$convertedChar = iconv('ISO-IR-166', "UTF-8", '¤');

returns "ยค" instead of "ค"?

also

$convertedChar = iconv('ISO-IR-166', "UTF-8", 'Á');

returns false instead of "ม".

  • Probably because `¤` is _not_ encoded in `ISO-IR-166` to begin with. What character encoding did you save the script file containing this code in? – CBroe Jul 06 '21 at 09:41
  • It saves as a UTF-8 – Marsa Baniasadi Jul 06 '21 at 09:47
  • So specifying `ISO-IR-166` as input charset would simply be a lie then … This feels like a constructed test scenario (and a badly constructed one, at that.) Can you explain what _actual_ problem you are trying to solve here? – CBroe Jul 06 '21 at 09:49
  • Even utf8_decode('¤') returns "¤" – Marsa Baniasadi Jul 06 '21 at 09:49
  • Yes, I defined it completely here: https://stackoverflow.com/questions/68130456/php-iconv-character-encoding-from-thai-iso-8859-11-to-utf-8?noredirect=1#comment120470080_68130456 – Marsa Baniasadi Jul 06 '21 at 09:51
  • I get the string from the database which its saved character encoding is "ISO_IR 166" and I want to convert it to UTF-8 – Marsa Baniasadi Jul 06 '21 at 10:02
  • 1
    You can not reproduce that with an example like above, because the `¤` _is not_ in ISO-IR-166 encoding, if you saved your script file as UTF-8. And if it does not work with content read from the database - then that is likely not in ISO-IR-166 either. (_Stored in_ the database, is not necessarily the same as what you _read from_ the database. The character encoding of the connection might come into play here as well.) – CBroe Jul 06 '21 at 10:04
  • 1
    In regard to your example from the other question, where `¤` is _supposed to be_ `A4` - once you actually provide that character byte value as input, it works fine: https://3v4l.org/AIuMe – CBroe Jul 06 '21 at 10:07
  • This platform uses UTF-8. You cannot simply display other codings in a reproducible manner here. This requires a special function that uses the hexadecimal representation. Use plaese this function to show your input. //Returns a string with escaped chars in hexadecimal notation function strToHex2($str) { return '\x'.rtrim (chunk_split(strtoupper(bin2hex($str)), 2,'\x'),'\x'); } – jspit Jul 06 '21 at 10:45

1 Answers1

0

After all your helps I've got to this result:

$convertedChar = iconv('ISO-IR-166', "UTF-8", utf8_decode('¤'));