Jump to content

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!
Link to comment
https://forums.phpfreaks.com/topic/15105-including-php-in-an-rss-feed/
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]
[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?
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.