Questions about converting xml into arrays

Source: Internet
Author: User
The problem of converting xml into arrays is as follows: XMLcode & lt; root & gt; & lt; rows & gt; & lt; errMsgtext = & quot;/& gt; & lt; retValuetext = & quot; true & quot;/& gt; & xml conversion to an array
The existing xml is as follows:
XML code
  
  
   
    
    
   
   
    
    
    
    
    
    
    
   ....
   
  

The xml depth is unknown, but each node has the text attribute. Is there any way to convert it into the following array?
PHP code
  Array(    [rows] => Array        (            [errMsg] =>             [retValue] => true        )    [records] => Array        (            [productno] =>000321            [billno] =>            [orderno] =>D004410439            [out_trade_no] => 100001            [plcprem] =>0.0            [orderprem] =>50.0            [commision] =>0.0        )        .....)


------ Solution --------------------
Look at this

Http://weblog.thomassmart.com/2008/09/php-function-xml2array/
------ Solution --------------------
PHP code
$ S = <XML
  
   
    
    
   
   
    
    
    
    
    
    
    
   
  XML; $ obj = simplexml_load_string ($ s); $ r = array (); foreach ($ obj as $ name => $ nodes) {foreach ($ nodes as $ k =>v v) {$ t = (array) $ v-> attributes ()-> text; $ r [$ name] [$ k] = $ t [0] ;}} print_r ($ r );
------ Solution --------------------
Discussion
PHP code
$ S = <XML










......

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.