2013-10-10 21 views
0

所以即時嘗試從我的frontpage index.php上的文件feed.php(它的rss)顯示我的提要。但它喜歡它不能讀取我的輸入項''標題'從等當我將其加載到的index.php feed.php ....然而,似乎沒有在feed.php任何麻煩本身xml/rss文件中的數據庫輸出

的index.php我有以下代碼

$feed = simplexml_load_file('feed.php'); 
$counter = 0; 
$amount = 5; 
foreach($feed->channel->item as $item){ 
while ($counter<$amount) { 
    echo utf8_decode("<a href='{$item->link}'>{$item->title}</a><br>"); 
    echo utf8_decode("<i>{$item->pubDate} </i><br>"); 
    echo utf8_decode("{$item->description} <br><br>"); 
break; 
} 
$counter ++; 
} 

這在feed.php

<rss version="2.0"> 
<channel> 
    <title>This is the title</title> 
    <link>http://www.someweirdurl.com</link> 
    <description>Just a testpage</description> 
    <?php 
    require_once 'dbconn.php'; 

    $sql = "SELECT * FROM feeds"; 
    $obj_result = $obj_con->query($sql); 
    while ($row = $obj_result->fetch_object()) { 
    ?> 
    <item> 
    <title><?php echo $row->artikel_title; ?></title> 
    <link><?php echo $row->artikel_url; ?></link> 
    <description><?php echo $row->artikel_tekst; ?></description> 
    <author><?php echo $row->artikel_forfatter; ?></author> 
    <category><?php echo $row->artikel_kategori; ?></category> 
    <subDate>Fri, 05 Jul 2013 15:29:07 +0200</subDate> 
    </item> 
    <?php 
    } 
    ?> 
</channel> 
</rss> 

我試圖打印在index.php文件,這讓我輸出,如

[author] => SimpleXMLElement Object 

它就像它們是空.. 雖然得到SUBDATE(作爲唯一的一個)

[subDate] => Fri, 05 Jul 2013 15:29:07 +0200 

可能由於subDate是我沒有從數據庫中取出的唯一一個.. 那麼,我有什麼不同,使它與我的數據庫中的數據工作..?

回答

1

如果feed.php,U必須把所有的XML字符串變量像$ my_xml,

然後後的PHP代碼,使用header ("Content-Type:text/xml");更改文件類型爲XML。

然後回顯$ my_xml。

就是它