2010-07-22 31 views
0

乾草,我試圖從wordpress博客解析RSS訂閱源。到目前爲止,一切工作如預期,這裏是我的代碼使用SimpleXmlElement從wordpress RSS訂閱獲取作者問題

<?php 
    $feedUrl = "FEED URL"; 
    $rawFeed = file_get_contents($feedUrl); 
    $xml = new SimpleXmlElement($rawFeed); 
    $channel = $xml->channel; 
    $items = $channel->item; 
    foreach($items as $item){ 
     echo "<a href='".$item->link."'>".$item->title."</a>"; 
     echo $item->description; 
     echo $item->pubDate; 

    }  

?> 

但是,我似乎有問題得到該職位的作者。數據已經在某個地方,因爲當Safari呈現作者出現的Feed時。

這裏是我的RSS提要

SimpleXMLElement Object 
(
[@attributes] => Array 
    (
     [version] => 2.0 
    ) 

[channel] => SimpleXMLElement Object 
    (
     [title] => My Blog title 
     [link] => http://blog.com/new/blog 
     [description] => Just another WordPress site 
     [lastBuildDate] => Thu, 22 Jul 2010 08:02:19 +0000 
     [language] => en 
     [generator] => http://wordpress.org/?v=3.0 
     [item] => Array 
      (
       [0] => SimpleXMLElement Object 
        (
         [title] => Second post 
         [link] => http://blog.com/new/blog/?p=5 
         [comments] => http://blog.com/new/blog/?p=5#comments 
         [pubDate] => Thu, 22 Jul 2010 08:02:19 +0000 
         [category] => SimpleXMLElement Object 
          (
          ) 

         [guid] => http://blog.com/new/blog/?p=5 
         [description] => SimpleXMLElement Object 
          (
          ) 

        ) 

       [1] => SimpleXMLElement Object 
        (
         [title] => Hello world! 
         [link] => http://blogl.com/new/blog/?p=1 
         [comments] => http://blog.com/new/blog/?p=1#comments 
         [pubDate] => Thu, 22 Jul 2010 07:22:40 +0000 
         [category] => SimpleXMLElement Object 
          (
          ) 

         [guid] => http://blog.com/new/blog/?p=1 
         [description] => SimpleXMLElement Object 
          (
          ) 

        ) 

      ) 

    ) 

任何幫助將是真棒!

感謝

+0

請顯示Feed的源代碼。 – 2010-07-22 09:51:21

+0

添加提要源代碼 – dotty 2010-07-22 10:00:29

回答

3

在WordPress的RSS源,作者信息是在<dc:creator>標籤。看看它是否也適用於您的Feed。

由於標記名稱中含有冒號,XML解析器會吞下該標記。

請參閱this question瞭解如何讓這些標籤顯示。

+0

謝謝,此答案中的鏈接解釋瞭如何獲取作者(創作者)。 – dotty 2010-07-22 10:13:53