Encoding issues with XMLWriter (PHP)

后端 未结 1 508
余生分开走
余生分开走 2021-01-15 12:45

Take this simple PHP code:

$xmlWriter = new XMLWriter();
$xmlWriter->openURI(\'php://output\');
$xmlWriter->startDocument(\'1.0\', \'utf-8\');

$xmlWri         


        
相关标签:
1条回答
  • 2021-01-15 13:21

    I'm not sure where you got the idea that XMLWriter converts encodings. It doesn't. You must supply it with utf-8. It can output different encodings, but input strings must be utf-8.

    One of two things may be going on here:

    1. Whatever you are using to view your output document is interpreting the string as win-1252. If you are viewing your output in a browser, you may need to set the content-type header like so: header('Content-Type: application/xml; charset=UTF-8');
    2. You stored your data in your database incorrectly, and your "é" is actually two unicode characters "é". Fixing this is difficult.
    0 讨论(0)
提交回复
热议问题