如何在RSS中显示图像? [英] How to display image in RSS?

查看:67
本文介绍了如何在RSS中显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个非常简单的RSS频道,该频道将显示sinfest.net上当日的漫画,但是我不能强迫它显示除链接标题以外的任何内容. 链接到其中一个代码版本:

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]*)"><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/</link>
                <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>';
?>

仅RSS的代码(我没有删除PHP变量):

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/</link>
        <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.

推荐答案

您最好的选择是CDATA该图像部分(或者,您也可以"htmlentities()"它,但这更好!)

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

<description><![CDATA[<img src="' . $image . '" />]]></description>

这篇关于如何在RSS中显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆