PHP generated XML in Flash to get the final solution garbled

Source: Internet
Author: User
Tags final php code php script
The most afraid of the problem with the unthinkable to fight, to see who cattle nose. Have not been in the code for a long time encountered obstacles, and today unexpectedly met a small tea bag--php generated XML, to flash access is garbled.

-->After exploring the final solution. Recorded, and the general solution was also recorded in passing. If you also encounter Xml<->flash garbled situation, you can quickly check:
1. Be sure that the XML is absolutely free of problems:
First of allFlashRead XML appears garbled involves system.usecodepage this static property property
Official description: "A Boolean value that tells Flash Player which the code page to the interpret external text files." The default is False.
If we use UTF8 encoded external text file, php100.com do not care about it, using a UTF8 encoded text file and the text appears in the word, you need to set it to true Square can let Flash read characters not garbled.
AS3 can be first import Flash.system.System, and then set system.usecodepage=true;
2. You want PHP to generate UTF-8 encoded XML:
To have Chinese characters in XML, it is best to use UTF-8 encoding. Declared as $dom_xml = new DOMDocument (' 1.0′, ' utf-8′) before using DOM to create XML, and the second parameter corresponds to the encoding value of the XML Document declaration section. But note: This is just a declarative encoding, using $dom_xml->savexml (), the actual generated XML file is the same as the PHP script source file encoding format, that is, "What is your PHP code, the generated file is what code." ”
3. XML file declaration code for UTF-8, Flash, regardless of usecodepage set why the value is read or garbled
This is often the case, usually because: although the declaration is partly UTF-8, the file itself is not UTF-8 (I am ANSI-encoded, Khan).
That will lead to a serious problem: Firefox browser can explain the XML normally, but IE (including TT and other IE kernel browser) but prompted the existence of the wrong characters, Flash also display garbled!
There are two ways to handle this situation:
Change the XML declaration part to a UTF-8, such as GB2312, and then set the usecodepage=true of the Flash;
Open XML in Notepad, save as UTF-8 using the Save As command
This means that the encoding declaration matches the encoding of the file itself, and cannot be named inconsistent.
4. The PHP source file is not UTF8 encoded, how do I generate the XML that allows Flash to support Chinese characters? That's the situation I'm in:
PHP is saved by ANSI, and XML generated using DOM is naturally ANSI, php100.com this encoded XML file contains Chinese characters, even if the declaration is encoded as UTF-8, it cannot be read correctly.
In this premise, to flash read XML correctly does not appear garbled, you must set encoding for GB2312.
and PHP's Dom can not use GB2312 to write Chinese characters (puzzled, ask the talent to the maze)? If new DOMDocument (' 1.0′, ' gb2312′ '), an error occurs while saving the XML: "Output conversion failed due to conv error, bytes 0xCE 0xd2 0x5d 0x5d" and so on. In other words, my ANSI PHP can only generate XML files declared as UTF-8 but actually ANSI, which of course Flash reads garbled (refer to 3rd).
My Solution:
After PHP generated XML with UTF-8 declaration, add a step: Open the XML file rewrite the header declaration to replace the UTF-8 with GB2312. Hey, flash,ie,ff is not wrong!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.