-1
4

1 回答 1

1

It looks like all you need to do is echo $row['data'];, the data is in Windows-1252 and your page's headers are in Windows-1252 as well. No conversion to UTF-8 required.

If you didn't realize your data is in windows-1252, and so have set encoding="UTF-8" in your xml, you shoiuld set it to encoding="Windows-1252".


If you want to use UTF-8, you should first start by setting your connection to UTF-8:

mysql_set_charset( "utf8" );
// or $mysqli->set_charset( "utf8" );

Before you make any queries.

After that you need to fix your http headers:

<?php
header( "Content-type: application/xml; charset=utf-8");

And of course, not call utf8_decode. Never call utf8_decode or utf8_encode unless you really know what you're doing. For starters, these functions work on ISO-8859-1->UTF-8 (and vice versa) conversions (the real ISO-8859-1, not the browser "ISO-8859-1" which is actually just Windows-1252) and are not some magic unicode wand.

There are many other things to do if you want to take utf-8 route, but these two will fix your immediate problem.

于 2012-12-10T16:23:02.163 回答