October 8, 2018
How to convert xml into array in php
How to convert xml into array in php
In this tutorial we are going to see how to convert xml into array in php.
In some case while calling external api calls,it gives the response as XML format at that we need to convert convert xml into array in php.
SimpleXML is a PHP extension that allows us to easily manipulate and get XML data.
we are going to use SimpleXML to convert xml into array in php.
Eaxmple :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php $XMLData = "<?xml version='1.0' encoding='UTF-8'?> <note> <to>Jegadeesh</to> <from>Jansi</from> <heading>Reminder</heading> <body>Make a meeting regarding project!</body> </note>"; $array = json_decode(json_encode((array)simplexml_load_string($myXMLData)),true); echo '<pre>'; print_r($array); |