A simple XML Data transformation method for arrays

Source: Internet
Author: User
Tags cdata

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

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.