8

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)

Rella
  • 65,003
  • 109
  • 363
  • 636
  • There are numerous methods posted in the comments at http://www.php.net/manual/en/function.utf8-encode.php#97533 on how to achieve this – Mark May 10 '10 at 22:02

2 Answers2

8

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
  • 73,842
  • 19
  • 118
  • 155
  • 4
    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 May 10 '10 at 22:06
  • 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 May 10 '10 at 22:10
  • @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 May 11 '10 at 08:02
  • Okay, is there a way to enforce falling back to latin-1 or ascii instead of throwing an error? – MrMesees Sep 22 '16 at 13:57
-15

I have written an array with the values of the string. You just need to do this:

$string = str_replace("“","",$string);
$string = str_replace("â€Â","",$string);

And they are gone!

nanofarad
  • 40,330
  • 4
  • 86
  • 117
lalo
  • 1