views:

57

answers:

4

Does anyone has idea how to access HREF from the below object:

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [title] => Preview
            [rel] => enclosure
            [type] => image/jpeg
            [href] => http://a1.phobos.apple.com/us/r1000/008/Purple/94/ee/38/mzl.fupornmt.320x480-75.jpg
        )

)
+3  A: 

SimpleXML objects representing XML elements support array like access to the element attributes

(string)theSimpleXMLElementObject['href']

The (string) cast is needed if you wish to compare the attribute with a string or pass it into a function that requires a string. Otherwise, PHP treats the attribute as an object. (That applies if you use the attributes() method as well)

Alexandre Jasmin
A: 

Use simpleXML http://php.net/manual/en/book.simplexml.php

playcat
more precisely: http://www.php.net/manual/en/simplexmlelement.children.php
playcat
+2  A: 

Use SimpleXMLElement::attributes method:

$attrs = $obj->attributes();
echo $attrs['href'];
Anpher
A: 

I can't say "Vote Up", but as Anpher says, you just need to access the attribute:

$attrs = $obj->attribues(); // Gets you the "[@attributes]" array (which is a copy of the internal private property "attributes")

do_things_with($attrs['href']); // Accesses the element you want.
ssice