2010-10-27 65 views
0

没有人有知道如何从下面的对象访问HREF:访问一个类对象在PHP

表示像访问元素的XML元素支持阵列
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

的SimpleXML对象属性

(string)$simpleXMLElement['href'] 

的如果您希望将该属性与一个字符串进行比较或将其传递到需要字符串的函数,则需要使用转换。否则,PHP会将该属性视为一个对象。 (这适用如果您使用attributes()方法为好)

0

我不能说 “投票支持”,但作为Anpher说,你只需要访问属性:

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