Return to Snippet

Revision: 70086
at November 19, 2015 05:54 by kavikms


Initial Code
<?php
// function to convert xml to php array
function xml2Array($filename)
{
    $xml = simplexml_load_file($filename, "SimpleXMLElement", LIBXML_NOCDATA);
    $json = json_encode($xml);
    return json_decode($json,TRUE);
}

// function callback
$arr = xml2Array("Data.xml");
print_r($arr);
?>

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

Initial Description
Convert easily XML File or String to Associative Array in PHP

Initial Title
Convert XML to Array in PHP

Initial Tags
php, array, xml

Initial Language
PHP