XML/Array to Key value pair in PHP -


i have following output :

<table count="" time="0.010006904602051"> <item> <id>607</id> <name>mspot6071</name> <description>hip hop / raps</description> <type>3</type> <radio_folder_id/> <albumart> http://cdn.7static.com/static/img/sleeveart/00/009/560/0000956027_175.jpg </albumart> <albumart_300> http://cdn.7static.com/static/img/sleeveart/00/009/560/0000956027_350.jpg </albumart_300> <albumart_500> http://cdn.7static.com/static/img/sleeveart/00/009/560/0000956027_500.jpg </albumart_500> </item> <item> <id>48542614</id> <name>us pop - testb</name> <description>blues</description> <type>3</type> <radio_folder_id/> </item> </table> 

i want read output in form of key value pair , want store each value. eg want value of "name"

can please me code..i not getting clue of how do.

you can use simplexml extension functions achieve goals. extension can load xml file, string or html node. follow links more information each load function. explain here how load using simplexml_load_file. code:

<?php echo "<pre>";    $xml = simplexml_load_file("name.xml");     print_r($xml);     echo "</pre>";  ?> 

will return this:

simplexmlelement object (     [@attributes] => array         (             [count] =>              [time] => 0.011766910552979         )      [item] => array         (             [0] => simplexmlelement object                 (                     [id] => 607                     [name] => mspot6071                     [description] => hip hop / raps                     [type] => 3                     [radio_folder_id] => simplexmlelement object                         (                         )                      [albumart] => http://cdn.7static.com/static/img/sleeveart/00/009/560/0000956027_175.jpg                     [albumart_300] => http://cdn.7static.com/static/img/sleeveart/00/009/560/0000956027_350.jpg                     [albumart_500] => http://cdn.7static.com/static/img/sleeveart/00/009/560/0000956027_500.jpg                 )              [1] => simplexmlelement object                 (                     [id] => 48542614                     [name] => pop - testb                     [description] => blues                      [type] => 3                     [radio_folder_id] => simplexmlelement object                         (                         )                  )          )  ) 

the information want, can accessed this:

<?php echo "<pre>";    $xml = simplexml_load_file("name.xml");     print_r($xml);     echo "</pre>";     echo "<pre>";     foreach($xml->children() $item){         $arr = get_object_vars($item);         foreach($arr $key=>$value){             echo "$key => $value" . php_eol;                     }     }     echo "</pre>"; ?> 

note accessed object first. can object vars dynamically navigate through object attributes.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -