i have a mysql table and some rows in a column contains ’
character. I have to echo the table content as xml. I am using this utf8_encode($row[\'data\'])
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"
.
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.