标签:test imp php alt key ring data png each
<?php $xml = <<<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> <Person> <Name>ruby</Name> <Age>24</Age> <Company> <Name>company</Name> </Company> </Person> </xml> XML; /** * @param SimpleXMLElement $xmls * @return array */ function parseXml($xmls) { $array = []; foreach ($xmls as $key => $xml) { /** @var SimpleXMLElement $xml */ $count = $xml->count(); if ($count == 0) { $res = (string) $xml; } else { $res = parseXml($xml); } $array[$key] = $res; } return $array; } $xmls = new SimpleXMLElement($xml); var_dump(parseXml($xmls));
结果:
php使用 SImpleXMLElement 把 xml 转为数组
标签:test imp php alt key ring data png each
原文地址:http://www.cnblogs.com/eleven24/p/7655607.html