嗨我試圖創建一個新聞源使用PHP。我編寫了一個連接到數據庫並檢索轉換成XML的信息的PHP代碼。該文件是一個.php文件,當我嘗試使用google reader進行解析時,它不起作用,因爲它只讀取XML文件。這裏是我的代碼:PHP爲RSS提要生成XML,但無法解析它,因爲該文件是PHP
<?php
header("Content-type: text/xml");
$dept = $_GET['dept'];
require_once ("/var/www/html/http/sass/includes/config.inc.php");
require_once ("sass_news.php");
$sassNews = paginate('sass_news', 'sass_news', $numResults, $offset, $order, $condition);
if($sassNews) {
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";
foreach($sassNews as $newsDetail){
$xml_output .= "\t<entry>\n";
$xml_output .= "\t\t<date>" . $newsDetail->news_start_date . "</date>\n";
$xml_output .= "\t\t<text>" . $newsDetail->news_body_en . "</text>\n";
$xml_output .= "\t</entry>\n";
}
$xml_output .= "</entries>";
echo $xml_output;
}
?>
您可以將文件擴展名設置爲XML,然後讓Web服務器執行PHP代碼。你使用什麼網絡服務器? –
如果通過將字符串捆綁在一起編寫XML,則可能會生成無效的XML。使用XML庫構建XML,[驗證](http://validator.w3.org/feed/) – Quentin