开发者

php generates xml for RSS feed but cannot parse it because the file is php

Hi Im trying to create a news feed using php. I have a php code written which connects to the database and retrieves information which is converted into XML开发者_运维技巧. The file is however a .php and when I try to parse it using google reader it dosen't work because it only reads files which are XML. Here's my code:

<?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;

}
?>


Try header('Content-disposition: attachment; filename=somename.xml'); at the top of the script. 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.


Have you read the RSS specification, that doesn't look like valid markup to me. It should have an rss node, a channel node and lots of other goodies. Also your content-type should be application/rss+xml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜