解析错误 - 使用CodeIgniter创建RSS源

Hey guys, I'm creating an rss feed with codeigniter and I get the specific error: XML Parsing Error: junk after document element Location: http://mysite.com/feeds/latest

After googling it and not being able to find a solution to my issue (despite a ton of results) I came here for some advice.

I have

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>

Followed by my websites title, link, description, pubdate, dc:date tags.

Followed by a foreach statement that loops results like so:

<?php foreach($feedResults as $feedItem): ?>
 <item>
       <title><?php echo $feedItem->title; ?></title>
          <link><?php echo site_url('/'.$feedItem->ID) ?></link>
          <guid><?php echo site_url('/'.$feedItem->ID) ?></guid>
    <description>descri[</description>
          <pubDate><?php echo date ('r', $feedItem->time());?></pubDate>
    </item>        
    <?php endforeach; ?>

My codeigniter controller doesn't do much besides retrieve $feedResults, sets the header to : header("Content-Type: text/xml"); and then passes the results to the view.

Thanks guys.

"Location: http://mysite.com/feeds/latest" looks like an HTTP header (location headers are how redirects work). Are you passing a URL that redirects to another URL to an XML parser that can't follow redirects?

If you save your RSS feed off with a .html extension you'll see that it's not RSS at all, it's an HTML error page:

ErrorException [ Parse Error ]: syntax error, unexpected T_STRING

APPPATH/views/feeds_latest_view.php [ 1 ]

1 <?xml version="1.0" encoding="UTF-8"?>
2 <rss xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
3   <channel>
4 
5     <title>Amazon.com Gold Box Deals</title>
6     <link>http://www.amazon.com/gp/goldbox</link>
  1. {PHP internal call} » MY_Exceptions::shutdown_handler(arguments)

My guess is that you have PHP short_tags enabled, which means <? is shorthand for <?php and opens a PHP code block. PHP is choking when it sees the <?xml as it tries to interpret the XML processing directive as a block of PHP code.

To fix this, turn off short_tags in php.ini. Or workaround it by writing PHP code to emit the directive:

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>