2012-02-16 109 views
-1

我試圖讓titlelink從這個XML飼料:的SimpleXML如何讓飼料

<item> 
    <title>A title</title> 
    <link>http://example.com</link> 
</item> 

這怎麼可能?我是PHP新手,我試圖弄清楚它。這是我迄今爲止所擁有的。

<?php 
    include 'http://example/forum/index.php?action=.xml;type=rss'; 

    $channel = new SimpleXMLElement($xmlstr); 

     echo $channel->$item[0]->title; 
?> 

但它不起作用。

+0

要開始,它的項目不是$ item – 2012-02-16 13:22:59

回答

0

你可以試試這個

$xml = simplexml_load_string($xmlstr); 
foreach($xml->item as $items){ 
     echo $items->title; 
} 
2

include只是將文件放入從腳本的輸出。所以不要使用它。

new SimpleXMLElement創建一個元素並且您想要一個文檔。所以不要使用它。

$xmlstr未定義。所以不要使用它。

使用simplexml_load_file