redyard Posted September 7, 2007 Share Posted September 7, 2007 Hi all, Simple question - is it possible to pass xml to php, and how would I go about doing this. ry. Quote Link to comment https://forums.phpfreaks.com/topic/68333-passing-xml-to-php/ Share on other sites More sharing options...
jitesh Posted September 7, 2007 Share Posted September 7, 2007 http://www.phpfreaks.com/forums/index.php/topic,134298.msg565373.html#msg565373 Quote Link to comment https://forums.phpfreaks.com/topic/68333-passing-xml-to-php/#findComment-343580 Share on other sites More sharing options...
Barand Posted September 7, 2007 Share Posted September 7, 2007 A simple example using simplexml <?php $inventory = array(); $xml = simplexml_load_string ("<inventory> <widget> <name>One</name> <color>Red</color> <weight>5</weight> <price>15</price> </widget> <widget> <name>Two</name> <color>Blue</color> <weight>8</weight> <price>21</price> </widget> <widget> <name>Three</name> <color>Green</color> <weight>3</weight> <price>12</price> </widget> <widget> <name>Four</name> <color>Red</color> <weight>15</weight> <price>35</price> </widget> </inventory>"); $xp = $xml->xpath('//widget'); $count = 0; foreach ($xp as $w) { $inventory[$count] = array (); foreach ($w->children() as $child ) { $inventory[$count][] = (string)$child; } ++$count; } echo '<pre>', print_r($inventory, true), '</pre>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/68333-passing-xml-to-php/#findComment-343608 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.