2012-01-22 63 views
0

如果有人能解釋一下如何訪問這個xml feed的'item'部分。這是文件的VAR_DUMP。即時通訊使用simplexml_load_string拉從谷歌的飼料,但如何我可以訪問到「項」內容在php解析後訪問xml對象

object(SimpleXMLElement)[1] 
    public '@attributes' => 
    array 
     'version' => string '2.0' (length=3) 
    public 'channel' => 
    object(SimpleXMLElement)[2] 
     public 'generator' => string 'NFE/1.0' (length=7) 
     public 'title' => string 'running barefoot - Google News' (length=30) 
     public 'link' => string 'http://news.google.com/news?pz=1&ned=us&hl=en&q=running+barefoot' (length=64) 
     public 'language' => string 'en' (length=2) 
     public 'webMaster' => string '[email protected]' (length=24) 
     public 'copyright' => string '©2012 Google' (length=17) 
     public 'pubDate' => string 'Sun, 22 Jan 2012 04:38:34 GMT' (length=29) 
     public 'lastBuildDate' => string 'Sun, 22 Jan 2012 04:38:34 GMT' (length=29) 
     public 'image' => 
     object(SimpleXMLElement)[3] 
      public 'title' => string 'running barefoot - Google News' (length=30) 
      public 'url' => string 'http://www.gstatic.com/news/img/logo/en_us/news.gif' (length=51) 
      public 'link' => string 'http://news.google.com/news?pz=1&ned=us&hl=en&q=running+barefoot' (length=64) 
     public 'item' => 
     array 
      0 => 
      object(SimpleXMLElement)[4] 
       ... 
      1 => 
      object(SimpleXMLElement)[5] 
       ... 
      2 => 
      object(SimpleXMLElement)[6] 
       ... 
      3 => 
      object(SimpleXMLElement)[7] 
       ... 
      4 => 
      object(SimpleXMLElement)[8] 
       ... 
      5 => 
      object(SimpleXMLElement)[9] 
       ... 
      6 => 
      object(SimpleXMLElement)[10] 
       ... 
      7 => 
      object(SimpleXMLElement)[11] 
       ... 
      8 => 
      object(SimpleXMLElement)[12] 
       ... 
      9 => 
      object(SimpleXMLElement)[13] 
       ... 
     public 'description' => string 'Google News' (length=11) 

回答

2

看起來你可以訪問像這樣的「項目」的成員變量:$yourObject->channel->item

1

有你在你問之前試圖尋找?有很多教程如何解析RSS提要 - for example

foreach($yourObject->channel->item as $item) 
{ 
    echo $item->title; 
    echo $item->link; 
} 
+0

謝謝您的回答。我做了很多搜索,但需要一點幫助。 – Cjueden