views:

583

answers:

4

I got a .vcf file with parts encoded as UTF-8:

CATEGORIES;CHARSET=UTF-8:Straße & –dienste

Now "–" should be a "-" and "Straße" should convert to "Straße".

I tried

  • utf8_decode()
  • iconv()
  • mb_convert_encoding()

And have been playing with several output encoding options like

  • header('content-type: text/html; charset=utf-8');
  • mb_internal_encoding('UTF-8');
  • mb_http_output( "UTF-8" );

But I don't get the wanted results - instead: "StraÃ?e & â??dienste"

Anyone getting that knot out of my brain? Thanks a lot.

A: 

You may actually want to try utf8_encode(). I had a similar problem when retrieving UTF-8 encoded information from MySQL and displaying it on a UTF-8 HTML page.

Vance Lucas
A: 

forgot to mention: there is no MySQL...

plain php ;-)

echo "Straße & –dienste";

echo utf8_decode("Straße & –dienste");

should somehow become "Straße & -dienste"... but won't, won't, won't

+1  A: 

solved.

i had to convert the PHP file back to ISO-8859-1 (instead of UTF-8).

thought that would make no difference, but it does!

Did you try to utf8_encode() the input, as PHP reads it in assuming it is not, and thus utf8_decode() on unencoded input is useless.
nikc
I haven't had much luck working with text editors that truly support UTF-8 editing. They will typically take whatever codepage the OS is using (ISO-8859-1 = default for US/Western Europe).
spoulson
A: 

I don't have an answer for you, as I'm not sure I understand fully what you are trying to do (read a .vcf file in PHP?)....

But a clue is this: "Straße" is "Straße" encoded in UTF-8, but then interpreted as Latin1 (or Windows-1252).

MtnViewMark