1, the following code error:
<?php
$xml = "<xml> <ToUserName><! [Cdata[touser]]></tousername> <FromUserName><! [Cdata[fromuser]]></fromusername> <CreateTime>1348831860</CreateTime> <MsgType><! [Cdata[text]]></msgtype> <Content><! [Cdata[this is a test]]></content> <MsgId>1234567890123456</MsgId> </xml> ";
$obj =simplexml_load_string ($xml, ' simplexmlelement ', libxml_nocdata);
Var_dump ($obj);
$obj 1=simplexml_load_string ($xml, ' simplexmlelement ');
Var_dump ($obj 1);
?>
PHP Debug Error Tip: Warning:simplexml_load_string (): Entity:line 1:parser error:StartTag:invalid element name in C:\wamp64\www 1\test1.php on line 4
2, later re-wrote the XML data, debugging passed, the return value is successful
<?php
$xml = "<xml>
<ToUserName>
<! [cdata[touser]]>
</ToUserName>
<FromUserName>
<! [cdata[fromuser]]>
</FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType>
<! [cdata[text]]>
</MsgType>
<Content>
<! [Cdata[this is a test]]>
</Content>
<MsgId>1234567890123456</MsgId>
</xml> ";
$obj =simplexml_load_string ($xml, ' simplexmlelement ', libxml_nocdata);
Var_dump ($obj);
$obj 1=simplexml_load_string ($xml, ' simplexmlelement ');
Var_dump ($obj 1);
?>
3, note the difference after adding libxml_nocdata parameters, the results are as follows:
Var_dump ($obj) is as follows:
C:\WAMP64\WWW1\TEST1.PHP:20:
Object (SimpleXMLElement) [1]
Public ' tousername ' and ' = String '
Touser
' (length=12)
Public ' fromusername ' and ' = String '
Fromuser
' (length=14)
Public ' createtime ' = String ' 1348831860 ' (length=10)
Public ' msgtype ' and ' = String '
Text
' (length=10)
Public ' Content ' = = String '
This is a test
' (length=20)
Public ' MsgId ' = String ' 1234567890123456 ' (length=16)
var_dump($obj1)如下:
C:\WAMP64\WWW1\TEST1.PHP:22:
Object (SimpleXMLElement) [2]
Public ' tousername ' =
Object (SimpleXMLElement) [3]
Public ' fromusername ' =
Object (SimpleXMLElement) [4]
Public ' createtime ' = String ' 1348831860 ' (length=10)
Public ' msgtype ' =
Object (SimpleXMLElement) [5]
Public ' Content ' =
Object (SimpleXMLElement) [6]
Public ' MsgId ' = String ' 1234567890123456 ' (length=16)
PHP function simplexml_load_string go to XML pits