[英]php generates xml for RSS feed but cannot parse it because the file is php
嗨,我正在嘗試使用 php 創建新聞提要。 我編寫了一個 php 代碼,它連接到數據庫並檢索轉換為 XML 的信息。 然而,該文件是 a.php,當我嘗試使用谷歌閱讀器解析它時它不起作用,因為它只讀取 XML 文件。 這是我的代碼:
<?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;
}
?>
嘗試header('Content-disposition: attachment; filename=somename.xml');
在腳本的頂部。 However, if Google Reader is going to allow only URLS which literally end in .xml
, then you'll need to reconfigure your server to treat.xml files as PHP scripts and rename this script to whatever.xml
.
您是否閱讀過RSS 規范,對我來說這看起來不像是有效的標記。 它應該有一個rss
節點、一個channel
節點和許多其他好東西。 您的內容類型也應該是application/rss+xml
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.