XML To Array With PHP
In
this example. To convert an XML document to a multidimensional array,
and take XML namespaces into account. Here, simpleXmlIterator is your
friend and the code has been bundled into an easy to use class to
convert any XML string into a array.
AN XML STRING
<movies> <movie> <title>Fist Full Of Dollars</title> <actor>Clint Eastwood</actor> <actor>Marianne Koch</actor> <actor> Wolfgang Lukschy</actor> <director>Sergio Leone</director> <year>1964</year> </movie> <movie> <title>Fist Full Of Dollars</title> <actor>Clint Eastwood</actor> <actor>Klaus Kinski</actor> <director>Sergio Leone</director> <year>1965</year> </movie> <movie> <title>The Good The Bad and the Ugly</title> <actor>Clint Eastwood</actor> <actor>Lee Van Cleef</actor> <actor>Eli Wallach</actor> <director>Sergio Leone</director> <year>1966</year> </movie> </movies>
THE CODE
USAGE
RESULT
Array ( [movie] => Array ( [0] => Array ( [title] => Array ( [0] => Fist Full Of Dollars ) [actor] => Array ( [0] => Clint Eastwood [1] => Marianne Koch [2] => Wolfgang Lukschy ) [director] => Array ( [0] => Sergio Leone ) [year] => Array ( [0] => 1964 ) ) [1] => Array ( [title] => Array ( [0] => Fist Full Of Dollars ) [actor] => Array ( [0] => Clint Eastwood [1] => Klaus Kinski ) [director] => Array ( [0] => Sergio Leone ) [year] => Array ( [0] => 1965 ) ) [2] => Array ( [title] => Array ( [0] => The Good The Bad and the Ugly ) [actor] => Array ( [0] => Clint Eastwood [1] => Lee Van Cleef [2] => Eli Wallach ) [director] => Array ( [0] => Sergio Leone ) [year] => Array ( [0] => 1966 ) ) ) )
0 comments:
Post a Comment