2011-10-03 99 views
1

你好,我想爲我的網站的XML飼料:獲取XML飼料和輸出

http://buildworx-mc.com/forum/syndication.php?fid=4&limit=5 

而且以這種格式顯示出來:

<ul> 
    <li><a href="linktothread"> Topic 1 </a> </li> 
    <li><a href="linktothread"> Topic 2 </a> </li> 
    <li><a href="linktothread"> Topic 3 </a> </li> 
</ul> 

我想最好的/最簡單的方法這是否使用PHP,那麼如何獲取XML並將它們顯示在列表項中?它會顯示在http://example.com,而飼料是http://example.com/forum

我試過其他問題的其他答案,但似乎沒有任何工作適合我。

回答

1

您可能需要使用命令「file_get_contents」來獲取遠程文件的副本,以便使用PHP解析它。我很驚訝這一步是必要的,因爲你說你想在你的網站上顯示你論壇的項目,所以你可以設置'feed'變量爲直接鏈接,假設所有內容都在同一個域中。如果沒有,這應該工作。

$feed = file_get_contents('http://buildworx-mc.com/forum/syndication.php?fid=4&limit=5'); 
    $xml = simplexml_load_string($feed); 

    $items = $xml->channel->item; 

    foreach($items as $item) { 
     $title = $item->title; 
     $link = $item->link; 
     $pubDate = $item->pubDate; 
     $description = $item->description; 

     echo $title . "<br>"; 

    // continue to format as an unordered list 

     }