views:

124

answers:

2

Ok, here's the specs:

Dev Server: Windows, WAMP, PHP 5+, Codeigniter

Live Server: Ubuntu Linux, PHP, CodeIgniter, LAMP

I get the following error in Firefox from my Live Server:

XML Parsing Error: junk after document element Location: http://www.mysite.com/feed/rss2/ Line Number 2, Column 1:

*syntax error, unexpected T_STRING in ...rss2.php*

HOWEVER, everything works like a beaut in Windows, in my Dev Environment.

Can anyone help me?


Here's the code:

function rss2() {
 @header("Content-Type: text/xml");
 $settings = $this->db_model->get_db_settings();

 $data['encoding'] = 'utf-8';
    $data["feed_name"] = $settings["sitename"];
 $data["feed_url"] = base_url() . "feed/rss2";
 $data["page_description"] = "RSS Feed for " . $settings["sitename"];
 $data["page_language"] = "en-us";
 $data["creator_email"] = "[email protected]";

 $data["todays_date"] = date("c");     

 //Array?
 $rssfeed = $this->blog_model->get_blog_posts_by_status("published");

 $i = 0;
 foreach ($rssfeed as $row) {
  //feed the details into the array
  $rss_data[$i]["title"] = $row["title"];
  $rss_data[$i]["permalink"] = base_url() . "content/blog/" . $row["slug"];
  $rss_data[$i]["date"] = $row["date"];
  $rss_data[$i]["description"] = utf8_encode(html_entity_decode($row["content"], ENT_QUOTES));   
  $rss_data[$i]["category"] = "No Category";
  $i=1;
 }

 if ($i == 0) {
  $data["rss_data"] = NULL;
 } else {
  $data["rss_data"] = $rss_data;
 }

 $this->load->view("system/feed/rss2", $data);

}
A: 

OK, Someone help me out if this is all wrong. I fixed the problem on the Live server, and it's still ok on the development one. The only thing I did was take out the first line in the xml document:

<?xml version="1.0" encoding="UTF-8"?>

Now the rss2.php file looks like this:

<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom"&gt;
    <channel>
    <atom:link href="<?php echo base_url() . 'feed/rss2/'; ?>" rel="self" type="application/rss+xml" />
    <title><?php echo $feed_name; ?></title>
    <link><?php echo $feed_url; ?></link>
    <description><?php echo $page_description; ?></description>
    <dc:language><?php echo $page_language; ?></dc:language>
    <dc:creator><?php echo $creator_email; ?></dc:creator>
    <dc:rights>Copyright <?php echo gmdate("Y", time()); ?></dc:rights>
    <dc:date><?php echo $todays_date; ?></dc:date>
    <admin:generatorAgent rdf:resource="http://www.codeigniter.com/" />

    <?php if ($rss_data == null) { ?>

     <item>
          <title>We're Sorry. There is no data to view.</title>
          <link><?php echo base_url(); ?></link>
          <guid><?php echo base_url(); ?>#When:<?php echo $todays_date; ?></guid>
          <description></description>
          <dc:subject></dc:subject>
          <dc:date><?php echo $todays_date; ?></dc:date>
        </item>

    <?php } else { ?>
    <?php foreach($rss_data as $row) { ?>

        <item>
          <title><?php echo xml_convert($row['title']); ?></title>
          <link><?php echo $row['permalink']; ?></link>
          <guid><?php echo $row['permalink']; ?>#When:<?php echo $row['date']; ?></guid>
          <description><?php echo xml_convert($row['description']); ?></description>
          <dc:subject><?php echo xml_convert($row['category']); ?></dc:subject>
          <dc:date><?php echo $row['date']; ?></dc:date>
        </item>

    <?php } } ?>

    </channel>
</rss>

Everything works like it should but is that correct? Shouldn't I have that encoding line? Let me know. Thanks in advance.

lucha libre
For me, this is basically closed.
lucha libre
If that solved your problem you should mark it as an answer, not retitle the question.
Dour High Arch
Sorry bout that. Will do.
lucha libre
+1  A: 

It sounds like the <? at the start of the XML declaration is misrecognised as a PHP code block, which the PHP interpreter then chokes on.

I seem to recall (though this might be quite wrong) that switching off short_open_tags support doesn't stop this problem.

The workaround is to emit the declaration from PHP itself, like so:

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