I use Easywechat to do reply text, the data obtained from the database is directly XML data, but the framework only comes with the XML format of the statement, all need to the XML data needed to be used to splice.
Search a lot of information said is very troublesome. PS: May be my level is not enough;-)
OK, nonsense not much to say, on the code:
Take this XML data string as an example $xml = "<item><title><! [cdata[Dear Customer:]]></title><content><! [cdata[]]></content><description><! [cdata[]]>
</description><picurl><! [Cdata[http://kantj.kxun.com/uploads/material/manage/45c48cce2e2d7fbdea1afc51c7c6ad26/[email protected]_ 1400140887.jpg]]>
</picurl><url><! [cdata[http://kantj.kxun.com/weixin.php/webapp/entrance?merchantid=9]]></url></item> "," <item ><title><! [cdata[Welcome to the home of Sam! ]]></title>
<content><! [cdata[]]></content><description><! [cdata[]]></description><picurl><! [Cdata[http://kantj.kxun.com/uploads/material/manage/45c48cce2e2d7fbdea1afc51c7c6ad26/[email protected]_ 1400138478.jpg]]></picurl><url><! [cdata[]]>
</Url></item> ";//The function converts XML data to simplement format//The third parameter represents the merging of CDATA nodes into a text node, otherwise CDATA resolves to null $xmls = Simplexml_ Load_string ($xml, ' simplexmlelement ', libxml_nocdata);//Convert the data to an array $arr = Json_decode (Json_encode ($XMLS), true); Var_ Dump ($arr);
Finally, you can see the converted array O (∩_∩) o haha ~
A simple XML Data transformation method for arrays