2010-03-05 106 views
5

我想写一个非常简单的RSS频道,它将显示来自sinfest.net当天的漫画,但我不能强迫它显示除链接标题外的任何内容。 链接代码版本之一:如何在RSS中显示图像?

<?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变量):

<?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> 

任何想法,我做错了,有些片建议也许?感谢提前。

+1

请在问题的代码。不得不下载压缩文件并提取压缩文件太费工夫,并且有可能失去未来内容的重要部分。 ...下载网站似乎也不工作。显而易见的“链接”不是链接。 – Quentin 2010-03-05 09:25:28

+0

对不起,我忘了这种可能性。 – brovar 2010-03-05 09:28:51

+0

尝试向我们展示RSS,而不是PHP。这是您遇到问题的RSS不是吗? – Quentin 2010-03-05 09:29:35

回答

12

你最好的赌注是CDATA该图像部分(或者你可以在“ヶ辆()”,但是,这个好!)

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

谢谢,它帮助 - 但令人惊讶的是“htmlentities”,而不是“CDATA”。 – brovar 2010-03-05 09:57:49

+0

很高兴帮助! – Fenton 2010-03-05 15:22:01