tags:

views:

244

answers:

2

I am trying to write a very simple RSS channel which would display the current day's comic strip from sinfest.net, but I cannot force it to display anything but the linked title. Link to one of the code versions:

<?php
$page = file_get_contents('http://www.sinfest.net/index.php');
$title = '';
$description = '';
$link = '';
$date = date("Y-m-d");
if (preg_match('~<img src="(http://sinfest\\.net/comikaze/comics/.*\\.gif)" alt="(.*)" border="0" />~isU', $page, $match)) {
        $title = $match[2];
        $description = "<img src='{$match[1]}'/>";
}
if (preg_match('~<a href="http://sinfest\\.net/archive_page\\.php\\?comicID=([0-9]*)"&gt;&lt;img src="images/prev_a.gif"~isU', $page, $match)) {
        $link = 'http://sinfest.net/archive_page.php?comicID=' . ($match[1]+1);
}
$ok = $title && $description && $link;
$image = "http://www.sinfest.net/comikaze/comics/" . $date . ".gif";
echo '<?xml version="1.0" encoding="ISO-8859-1" ?>';
echo '<rss version="2.0">
        <channel>
                <title>Latest Sinfest</title>
                <link>http://www.sinfest.net/&lt;/link&gt;
                <description>Latest Sinfest</description>
                <image>
                      <url>' . $image . '</url>
                      <title>' . htmlspecialchars($title) . '</title>
                      <link>' . htmlspecialchars($link) . '</link>
                </image>';
if ($ok):
echo '               <item>
                        <title>' . htmlspecialchars($title) . '</title>
                        <link>' . htmlspecialchars($link) . '</link>
                        <description><img src="' . $image . '" /></description>
                        <enclosure url="' . $image . '" type="image/jpeg" />
                </item>';
elseif (!isset($_GET['noerror'])): 
echo '                <item>
                        <title>Error parsing news.' . date('Y-m-d H:i:s') . '</title>
                        <link>about:blank</link>
                        <description>Error parsing news.</description>
                </item>';
endif;
echo '        </channel>
</rss>';
?>

The RSS-only code (I didn't remove the PHP variables):

<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
    <channel>
        <title>Latest Sinfest</title>
        <link>http://www.sinfest.net/&lt;/link&gt;
        <description>Latest Sinfest</description>
        <image>
            <url>' . $image . '</url>
            <title>' . htmlspecialchars($title) . '</title>
            <link>' . htmlspecialchars($link) . '</link>
        </image>
        <item>
            <title>' . htmlspecialchars($title) . '</title>
            <link>' . htmlspecialchars($link) . '</link>
            <description><img src="' . $image . '" /></description>
            <enclosure url="' . $image . '" type="image/jpeg" />
        </item>
    </channel>
</rss>

Any idea what am I doing wrong and some piece of advice maybe? Thank is advance.

+2  A: 

Your best bet is to CDATA that image section (alternatively you can "htmlentities()" it, but this is better!)

<description><![CDATA[<img src="' . $image . '" />]></description>
Sohnee
Thank you, it helped - but surprisingly the "htmlentities", not the "CDATA".
brovar
Glad it helped!
Sohnee
+2  A: 

I strongly recommend you using Feedwriter for creating RSS http://devkick.com/components/php/feedwriter/

Kirzilla
Thanks, I'll take a look at it :)
brovar