tags:

views:

30

answers:

1

Here is my XML:

["link"]=>
          array(2) {
            [0]=>
            object(SimpleXMLElement)#244 (1) {
              ["@attributes"]=>
              array(3) {
                ["type"]=>
                string(9) "text/html"
                ["href"]=>
                string(48) "http://twitter.com/MoodleDan/statuses/1226112723"
                ["rel"]=>
                string(9) "alternate"
              }
            }
            [1]=>
            object(SimpleXMLElement)#245 (1) {
              ["@attributes"]=>
              array(3) {
                ["type"]=>
                string(9) "image/png"
                ["href"]=>
                string(59) "http://a3.twimg.com/profile_images/226895523/Dan_normal.png"
                ["rel"]=>
                string(5) "image"
              }
            }
          }
          ["author"]=>
          object(SimpleXMLElement)#246 (2) {
            ["name"]=>
            string(14) "Dan Humpherson"
            ["uri"]=>
            string(16) "http://vl3.co.uk"
          }

The above XML is part of a larger array, but how do i get the

href ->          ["href"]=>
                    string(59) "http://a3.twimg.com/profile_images/226895523/Dan_normal.png"

Element to echo in PHP?

This is what I tried (Wrong I know)

 foreach ($entry->link as $img) {
            echo $img->href;
            echo "<img src='". $img ."' />";
           }
+3  A: 

To access a node's attributes you must use the attributes() function:

$xml = simplexml_load_string($string);
foreach($xml->foo[0]->attributes() as $a => $b) {
    echo $a,'="',$b,"\"\n";
}

Using your example:

foreach($entry->link as $link) {
    echo $link->attributes()->href;
}
rogeriopvl
+1 for using my example : )
danit