mysql utf8.xml,UTF-8,PHP和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;

else

return utf8_encode($in_str);

}

header("Content-type: text/plain;charset=utf-8");

$mystring = "Otivägen" // this is actually obtained from database;

$myxml = "

....

".$mystring."

....

";

$myxml = fixEncoding($myxml);

The actual XML output is below:

....

Otivägen

....

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

EDIT:

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!

解决方案

I think you did everything correctly, except that your terminal is in Latin-1.

The UTF-8 sequence for ä is C3 A4, which is ä if displayed as Latin-1.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值