You have recently used simplexmlelement to generate and parse XML.
Because we use PHP to develop this side using UTF-8 encoding, and the other side using GBK encoding, so encountered the Chinese character encoding problem.
It was later found that the internal encoding of XML and its head
<?xml version="1.0" encoding="gbk" ?>
There is an absolute relationship between the encoding declared in the UTF-8 encoded Chinese characters written to the object, the string returned by the Asxml method is GBK, no conversion is required, and vice versa.
Recommended children's shoes for working with XML in PHP use the SimpleXMLElement object, do not connect the string directly
Cases:
$STRXML ='<?xml version= "1.0" encoding= "GBK"?><SnsPropSet></SnsPropSet>'; $OBJXML =simplexml_load_string ($STRXML); $OBJXML->addattribute ('Snscid', $ This-intcid); $OBJXML->addattribute ('Snstid', $ This-Inttid); $OBJXML->addattribute ('Snspid', $ This-intpid); $intCount= $strCount =0; if(Is_int ($mixSnsAttrVal)) {$objXmlChild= $objXml->addchild ('Propint'); $intCount++; } Else{$objXmlChild= $objXml->addchild ('Propdyn'); $strCount++; } $objXmlChild->addattribute ('ID', $intSnsAttrId); $objXmlChild->addattribute ('V', $mixSnsAttrVal); $objXml->addattribute ('PROPINTC', $intCount); $OBJXML->addattribute ('Propdync', $strCount); $STRXML= $objXml->asxml ();
SimpleXMLElement object character encoding in PHP