I have a difficult one. I've built an RSS feed and included the 'enclosures' tag. I need to include a full URL rather than just the path for the enclosure so I've prefixed it with my site name and then added the path name from the database. The issue I have is that the site url displays in RSS readers when an RSS item does not have an attachment. I therefore need a way of just including URLs that contain files in the enclosures tag.
My current code is
Code: Select all
for($i=0;$i<$count; $i++) {
$subject = mysql_result($result,$i,'t1.Notice_Title');
$description = mysql_result($result,$i,'t1.Notice_Text');
// Clean the description
$description = str_replace ("&","",htmlspecialchars(strip_tags($description)));
$link = mysql_result($result,$i,'t1.Notice_Link');
//to record when the feed was published
$pubdate = mysql_result($result,$i,'t2.publish_up');
//format the date
$format = 'D, d M Y H:i:s O'; //or what ever format you choose (see the reference below)
$pubdate = date_format(date_create($pubdate), $format);
//get the image path then remove the first part of absolute path
$image = mysql_result($result,$i,'t1.Image');
$cropimagepath = substr($image, 26);
//get the enclosure path then remove the first part of absolute path
$attachment = mysql_result($result,$i,'t1.Attachment');
$cropattachpath = substr($attachment, 26);
echo '
<item>
<title>'.$subject.'</title>
<link>'.$link.'</link>
<description><![CDATA[<img src="http://www.mysite.com'.$cropimagepath.'" align=left>]]>
'.$description.'</description>
<pubDate>'.$pubdate.'</pubDate>
<enclosure url="http://www.mysite.com'.$cropattachpath.'" length="" type="application/pdf" />
</item>
';
Code: Select all
if (!empty($attachment) {
$cropattachpath = substr($attachment, 26);
$attachfinal = "http://www.mysite.com/'.$cropattachpath.'";
}
Code: Select all
<enclosure url="'.$attachfinal.'" length="200" type="application/pdf" />
Any ideas?
Shaun