Creating an RSS FEED

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Creating an RSS FEED

Post by psychotomus »

http://validator.w3.org/feed/check.cgi? ... 2Ffeed.rss = my validation. don't really understyand what is wrong with it.

help please.don't know what iswrong.
my code:

Code: Select all

 
        //create rss feed
$str = '<?xml version="1.0" encoding="utf-8"?>
        <rss version="2.0">
        <channel>';
        $result = mysql_query("SELECT * FROM themes WHERE pending='n' ORDER BY id DESC LIMIT 10");
        while($themes = mysql_fetch_object($result))
        {
        $descr = '<div class="entry">
                <p>
                    <img src="images/arrow.png" alt="" /> Name: <a href="' . $siteURL . "/themes/" . $themes->id . "/" .  clean_url($themes->name) . '/">' .  $themes->name . '</a><br />
                    <img src="images/arrow.png" alt="" /> Author: <a href="' . $siteURL . "/author.php?id=" . $themes->username . '">' . $themes->username . '</a><br />
 
                    <img src="images/arrow.png" alt="" /> Categories: ' . theme_cats($themes->id) . '<br />
                    <img src="images/arrow.png" alt="" /> Properties: <br />' .
                    theme_properties($themes->id) . '
                </p>
                <div class="demo">';
                
                 if(!is_dir("../testrun/wp-content/themes/$themes->id/"))
                 { 
                    $descr .=  'Demo (#)';
                } else 
                {
                    $descr .= '<a href="' . $siteURL . '/testrun/index.php?preview_theme=' . $themes->id . '" target="_blank" class="style1">Demo (#)</a>';
                } 
                $descr .= '</div> ';
        $str .= "
<item>
<title>$thems->name WP Theme</title>
<link>" . $siteURL . "/themes/" . $themes->id . "/" .  clean_url($themes->name) . "</link>
<guid>" . $siteURL . "/themes/" . $themes->id . "/" .  clean_url($themes->name) . "</guid>
<pubDate>" . date("D M j G:i:s T Y")   . "</pubDate>
<description>[CDATA[ " .     $descr      . "  ]]</description>
</item>";
        }
$str .= '</channel>
</rss>';
        $fp = fopen('../feed.rss', 'w');
        fwrite($fp, $str);
        fclose($fp);
 
zootboy
Forum Newbie
Posts: 11
Joined: Sun Aug 10, 2008 3:27 pm
Location: In a dumpster, with my laptop.

Re: Creating an RSS FEED

Post by zootboy »

Ya know, I don't think rss feed content is supposed to contain any html. I believe it should be plain text only, like this:

Code: Select all

 
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
  <channel>
    <title>MY SITE</title>
    <link>http://www.example.com</link>
    <description>My website. I put stuff on it.</description>
    <item>
       <title>August 4, 2008 - NEWS</title>
       <link>http://www.example.com/news</link>
       <description>News has been posted!</description>
    </item>
  </channel>
</rss>
 
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Creating an RSS FEED

Post by Christopher »

You might be able to use CDATA to put HTML is a block:

Code: Select all

<description>
<![CDATA[
<p>
<!-- Your HTML here -->
</p>
]]>
</description>
(#10850)
zootboy
Forum Newbie
Posts: 11
Joined: Sun Aug 10, 2008 3:27 pm
Location: In a dumpster, with my laptop.

Re: Creating an RSS FEED

Post by zootboy »

Even if it were possible to put HTML in rss feeds, most rss readers would ignore it. Rss feeds are supposed to be plain text, in my understanding. Here's the wikipedia article on it: http://en.wikipedia.org/wiki/RSS

As for the CDATA thing, did you look at the validation page? It has CDATA tags in it, but it still fails because of the HTML within the tags. It would appear that they do nothing.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Re: Creating an RSS FEED

Post by psychotomus »

I thought rss feeds was allows to have html tags?
zootboy
Forum Newbie
Posts: 11
Joined: Sun Aug 10, 2008 3:27 pm
Location: In a dumpster, with my laptop.

Re: Creating an RSS FEED

Post by zootboy »

Do you know what rss feeds are used for? They are supposed to be small, plain text news updates that link to a webpage. Even if you could put html in them, most rss readers would not process it.
Post Reply