Jump to content


Photo

Including PHP in an RSS Feed


  • Please log in to reply
5 replies to this topic

#1 neo926

neo926
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 20 July 2006 - 04:44 AM

So, I'm creating an RSS feed for a site.  It includes PHP code, as it pulls all the latest articles from the site's MySQL database when creating the feed.  However, when I display the XML file, it hasn't processed any of the PHP code I have in the feed.  Basically, my code looks like this:

<?php header('Content-type: text/xml'); ?>

<rss version="2.0">
<channel>
<title>Title</title>
<description>Description</description>
<link>http://link.com/</link>
<copyright>All material copyright 2006 their respective owners</copyright>

<?php

PHP code pulls data from db

?> 
     <item> 
        <title> <?php echo $myrow['title']; ?></title> 
        <description> <?php echo $myrow['teaser']; ?></description> 
        <link>http://link.com/index.php?id=<?php echo $myrow['id']; ?></link> 
     </item>    

<?php

}

?>

</channel>
</rss>

Now, I know this feed works, as it's basically the same code I have on a different site, and there are no problems displaying the RSS feed.  On this site, however, when you click on the XML link, it takes you to the XML page, only all the PHP code is sitting there, completely unparsed.

Is there something the site's server might not be capable of doing that is causing this problem?  Or am I not including something I should be?  Help!

#2 neo926

neo926
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 20 July 2006 - 01:18 PM

Did I post this in the wrong forum?

#3 helppingme

helppingme
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 01:31 PM

Go here for RSS & XML reader source code..

http://www.phpfreaks...c,101240.0.html

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 20 July 2006 - 01:34 PM

Go here for RSS & XML reader source code..

He is creating a feed, not a feed reader.

What file extension does this file have? In order to parse the php it'll either need the .php extension, or you'll need to setup your server to parse .xml as php.

#5 helppingme

helppingme
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 01:45 PM

Sorry for the post before, here is a php source code to parse XML.

<?php 
header("Content-Type: text/xml"); 
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; 
echo "<?xml-stylesheet href=\"/style/xml.css\" type=\"text/css\"?>";

echo "<!DOCTYPE rss PUBLIC \"-//Netscape Communications//DTD RSS 0.91//EN\""; 
echo " \"http://my.netscape.com/publish/formats/rss-0.91.dtd\">"; 
echo "<rss version=\"0.91\">"; 
echo "<channel>"; 
echo "<title>".htmlspecialchars($sitename)."</title>"; 
echo "<link>$siteurl</link>"; 
echo "<description>".htmlspecialchars($description)."</description>"; 
echo "<language>$xml_language</language>";
echo "<item>"; 
echo "<title>".htmlspecialchars($products_name)."</title>\n"; 
echo "<link>$siteurl$products</link>\n";
echo "<description>".htmlspecialchars($productdescription)."</description>\n";
echo "<price>$price_format</price>\n";
echo "</item>\n";} 
echo "</channel>\n"; 
echo "</rss>"; 
?>


#6 neo926

neo926
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 20 July 2006 - 11:15 PM

Go here for RSS & XML reader source code..

He is creating a feed, not a feed reader.

What file extension does this file have? In order to parse the php it'll either need the .php extension, or you'll need to setup your server to parse .xml as php.

I had it as an .xml file.  What do I need to do to parse .xml as php?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users