Convert XML to Array in PHP


/ Published in: PHP
Save to your folder(s)

Convert easily XML File or String to Associative Array in PHP


Copy this code and paste it in your HTML
  1. <?php
  2. // function to convert xml to php array
  3. function xml2Array($filename)
  4. {
  5. $xml = simplexml_load_file($filename, "SimpleXMLElement", LIBXML_NOCDATA);
  6. $json = json_encode($xml);
  7. return json_decode($json,TRUE);
  8. }
  9.  
  10. // function callback
  11. $arr = xml2Array("Data.xml");
  12. print_r($arr);
  13. ?>

URL: http://www.kodingmadesimple.com/2015/11/how-to-convert-xml-file-to-array-in-php.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.