French apostrophe char in mysql database?

后端 未结 1 480
时光说笑
时光说笑 2021-01-29 09:31

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\'])

相关标签:
1条回答
  • 2021-01-29 09:51

    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.

    0 讨论(0)
提交回复
热议问题