开发者

Accessing a class object in PHP

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

SimpleXMLElement Object
(
    [@attribut开发者_如何学Goes] => 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
        )

)


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

(string)$simpleXMLElement['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)


Use SimpleXMLElement::attributes method:

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


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


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜