tags:

views:

269

answers:

1

so for example this will turn 1251 into utf-8.

$utf8 = iconv('windows-1251', 'utf-8', $ansi);

But how to turn unknown (when it comes to us we do not know yet what format it is) ( in general any ) format (possibly known by Iconv ) to utf-8? (code sample)

+1  A: 

You cannot translate from an unknown character set, the best you can do is make a guess about the actual charset and use that guess as first parameter - you can use mb_detect_encoding() for that purpose.

soulmerge
could you please give some code example on how to do it?
Blender
mb_detect_encoding is limited to UTF-8 and UTF-7, ASCII, and a bunch of Japanese character sets. It won't work in the general case, and it can't, because there is no way of doing this for single-byte character sets - it would require an insane amount of context analysis, and that's just not feasible to implement. If you need to support arbitrary character sets, you'll need to require that the information is provided to you - or define a single, reasonable fallback if the input is not given, and not already UTF-8.
Michael Madsen
mb_detect_encoding() just makes a wild guess. It only works with an encoding with a good pattern, like UTF-8. It can't tell difference between ANSI and Latin-1.
ZZ Coder
@Ole Jak: What exactly do you need the code sample for? Do you want to know how to call a function? Or how to pass the return value to another function?
soulmerge