2012年12月4日 星期二

[RESOLVED] Warning: SimpleXMLElement::asXML(): string is not in UTF-8 in C:\XXXX

I've tried to export an XML file from php but failed to generate with Chinese Character. 

<?php
    $xml = new SimpleXMLElement('<xml/>');

    for ($i = 1; $i <= 10; ++$i) {
        $invoice = $xml->addChild('invoice');
        $invoice->addChild('customer', "客戶名稱");
        $invoice->addChild('invoiceNo', "invoiceNo $i");
    }

    Header('Content-type: text/xml');
    print($xml->asXML());
?>

The following error will be shown.
Warning</b>: SimpleXMLElement::asXML(): string is not in UTF-8 in C:\XXXX
Solution:
The error is caused by the incorrect encoding in the file. You might use your editor to open the file and change the encoding to UTF-8 for the resolution.


沒有留言:

張貼留言