(-xml-) GBK text

Source: Internet
Author: User
Create a simple XML structure, the source file with GBK writing results error, change to UTF8 format is correct, ask for reason?
This is the error of the GBK encoded file            header (' CONTENT-TYPE:APPLICATION/XML;CHARSET=GBK ');            $x = new DOMDocument (' 1.0 ', ' GBK ');            $a = $x->createelement (' a ');            $x->appendchild ($a);                        $you = $x->createtextnode (' you ');            $a->appendchild ($you);            echo $x->savexml ();

================================ The following is an error-U8 encoded source file =================================
This is the U8 encoded source file             header (' Content-type:application/xml;charset=utf-8 ');            $x = new DOMDocument (' 1.0 ', ' utf-8 ');            $a = $x->createelement (' a ');            $x->appendchild ($a);            $you = $x->createtextnode (' you ');            $a->appendchild ($you);            echo $x->savexml ();


Reply to discussion (solution)

The working character set for XML is Utf-8

If this is the cause of the working character set U8, then parameter two can specify encoding what else does it mean? In addition to error in the Conv errors what is wrong?

The working character set for XML is Utf-8

Conv Error conversion failed

Specifies the working character set, which is only available in parts of Microsoft (because XML was invented by Microsoft)

php5.3, you can read an XML document that is not a utf-8 character set

Does PHP have a way to output strings of XML objects in GBK format?

Conv Error conversion failed

Specifies the working character set, which is only available in parts of Microsoft (because XML was invented by Microsoft)

php5.3, you can read an XML document that is not a utf-8 character set

It's not exactly what I said.

Header (' CONTENT-TYPE:APPLICATION/XML;CHARSET=GBK '); $x = new DOMDocument (' 1.0 ', ' GBK '); $a = $x->createelement (' a ') ; $x->appendchild ($a);             $you = $x->createtextnode (iconv (' GBK ', ' utf-8 ', ' You ')), $a->appendchild ($you); Echo $x->savexml ();

You can see that the output is really GBK encoded content
That is, the XML document that can output the specified character set.

But this does not change the fact that the working character set is Utf-8

Conv error is the result of converting the internal utf-8 character set to the specified output character set.

$you = $x->createtextnode (' you '); When you are treated as a utf-8 character in GBK, you naturally get an error.

  • 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.