2010-10-27 67 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.