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.