Advertisement
hom3chuk

Untitled

Jun 18th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1.  
  2. <?php
  3. $xmlstr = <<<XML
  4. <?xml version='1.0' standalone='yes'?>
  5. <media:group>
  6.         <media:content url="http://www.url.com" bitrate="450" width="320" duration="32" />
  7.         <media:content url="http://www.url.com" bitrate="212" width="320" duration="32" />
  8. </media:group>
  9. XML;
  10.  
  11. $data = new SimpleXMLElement($xmlstr);
  12. $result = array();
  13.  
  14. foreach ($data->content as $entry){
  15.     $subResult = array();
  16.     $attribute = $entry->attributes();
  17.     foreach ($attribute as $key => $value){
  18.         $subResult[(string)$key] = (string)$value;
  19.     }
  20.   $result[] = $subResult;
  21. }
  22.  
  23. var_dump($result);
  24.  
  25. /*
  26. user@host ~ $ php test.php
  27. array(2) {
  28.   [0]=>
  29.   array(4) {
  30.     ["url"]=>
  31.     string(18) "http://www.url.com"
  32.     ["bitrate"]=>
  33.     string(3) "450"
  34.     ["width"]=>
  35.     string(3) "320"
  36.     ["duration"]=>
  37.     string(2) "32"
  38.   }
  39.   [1]=>
  40.   array(4) {
  41.     ["url"]=>
  42.     string(18) "http://www.url.com"
  43.     ["bitrate"]=>
  44.     string(3) "212"
  45.     ["width"]=>
  46.     string(3) "320"
  47.     ["duration"]=>
  48.     string(2) "32"
  49.   }
  50. }
  51.  
  52. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement