Jump to content

Archived

This topic is now archived and is closed to further replies.

neo926

Including PHP in an RSS Feed

Recommended Posts

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:

[code]<?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>
[/code]

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!

Share this post


Link to post
Share on other sites
Go here for RSS & XML reader source code..

http://www.phpfreaks.com/forums/index.php/topic,101240.0.html

Share this post


Link to post
Share on other sites
[quote]Go here for RSS & XML reader source code..[/quote]
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.

Share this post


Link to post
Share on other sites
Sorry for the post before, here is a php source code to parse XML.

[code]<?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>";
?>[/code]

Share this post


Link to post
Share on other sites
[quote author=thorpe link=topic=101190.msg400407#msg400407 date=1153402486]
[quote]Go here for RSS & XML reader source code..[/quote]
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.
[/quote]
I had it as an .xml file.  What do I need to do to parse .xml as php?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.