Posted By

kavikms on 11/19/15


Tagged

php array xml to


Versions (?)

Convert XML to Array in PHP


 / Published in: PHP
 

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

Convert easily XML File or String to Associative Array in PHP

  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. ?>

Report this snippet  

You need to login to post a comment.