UTF-8, PHP and XML Mysql


I am having great problems solving this one:

I have a mysql database encoding latin1_swedish_ci and a table that stores names and addresses.

I am trying to output a UTF-8 XML file, but I am having problems with the following string:

Otiv?gen it is being outputted as Otiv?¤gen when i vim the file. Also when opened it IE i get

"An invalid character was found in text content. Error processing resource"

I have the following code:

function fixEncoding($in_str)
    $cur_encoding = mb_detect_encoding($in_str) ;
    if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8"))
        return $in_str;
        return utf8_encode($in_str);

header("Content-type: text/plain;charset=utf-8");
$mystring = "Otiv?gen" // this is actually obtained from database;

$myxml = "

$myxml = fixEncoding($myxml);

The actual XML output is below:


Any ideas how I can output the file so in vim the file reads Otiv?gen and not Otiv?¤gen?


I did mysql_client_encoding() and got latin1
I then did mysql_set_charset()
and again ran mysql_client_encoding() and got utf8, but still the same outputting issues.

Edit 2

I have logged into the command line and run the query SELECT address1 FROM address WHERE id = 1000;

SELECT address1 FROM address WHERE id = 1000;
Current database: ftpuser_db

|   address1  |
| Otiv?gen 32 |
1 row in set (0.06 sec)

Thanks in advance!