I have a feed that has been working fine till I modified the feed to support iTunes, which uses namespaces. I am trying to get the information from the feed to display, but I am not having luck.
Here’s a snippet of the feed:
[code]
<?xml version=”1.0″?>
<rss xmlns:itunes=”http://www.itunes.com/dtds/podcast-1.0.dtd” version=”2.0″>
<channel>
<title>Company Podcasts</title>
<link>http://localhost</link>
<language>en-us</language>
<copyright>Copyright 2008</copyright>
<description><![CDATA[Description]]></description>
<itunes:subtitle>Title</itunes:subtitle>
<itunes:author>Name</itunes:author>
<itunes:summary><![CDATA[Description]]></itunes:summary>
<itunes:owner>
<itunes:name>Name</itunes:name>
<itunes:email>name@localhost</itunes:email>
</itunes:owner>
<itunes:keywords>keywords</itunes:keywords>
<itunes:image href=”http://localhost/file.jpg” />
<itunes:category text=”Government & Organizations”>
<itunes:category text=”Local”/>
</itunes:category>
<itunes:category text=”Religion & Spirituality”>
<itunes:category text=”Christianity”/>
</itunes:category>
<itunes:category text=”Religion & Spirituality”>
<itunes:category text=”Spirituality”/>
</itunes:category>
<webMaster>webmaster@localhost</webMaster>
<lastBuildDate>Tue, 17 Jun 2008 00:35:16 GMT</lastBuildDate>
<generator>PodAdmin – The Free Web-based Podcast Management Software http://podadmin.sourceforge.net</generator>
<item>
<title>Title</title>
<itunes:author>Pastor</itunes:author>
<itunes:subtitle></itunes:subtitle>
<itunes:summary>Text: Genesis 41:1-16
Date: 06/08/08</itunes:summary>
<enclosure url=”http://localhost/file.mp3″ length=”5554304″ type=”audio/mpeg”/>
<guid>http://localhost/file.mp3</guid>
<description><![CDATA[Text: Genesis 41:1-16
Date: 06/08/08]]></description>
<pubDate>Mon, 16 Jun 2008 00:00:00 CST</pubDate>
<itunes:duration>36:59</itunes:duration>
<itunes:keywords></itunes:keywords>
</item>
<item>
<title>Dysfunction, Deception, and the Plan of God</title>
<itunes:author>Pastor</itunes:author>
<itunes:subtitle></itunes:subtitle>
<itunes:summary>Text: Genesis 27:30 – 28:9
Date: 04/13/08</itunes:summary>
<enclosure url=”http://localhost/file.mp3″ length=”7145472″ type=”audio/mpeg”/>
<guid>http://localhost/file.mp3</guid>
<description><![CDATA[Text: Genesis 27:30 – 28:9
Date: 04/13/08]]></description>
<pubDate>Sun, 11 May 2008 00:00:00 CST</pubDate>
<itunes:duration>47:35</itunes:duration>
<itunes:keywords></itunes:keywords>
</item>
</channel>
</rss>
[code=php]
// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
// XML Feed
function processFeed($rss,$type) {
# Initiate variables
$_GET[‘newsoutput’] = “”;
$xml = “”;
if(fopen($rss, “r”)) {
$xml = simplexml_load_file($rss);
$itunes = $xml->children(‘http://www.itunes.com/dtds/podcast-1.0.dtd’);
} else {
echo ‘<p>error msg goes here</p>’;
}
$_GET[‘newsoutput’] = “<ul class=”standard”>”;
switch ($type) {
case “sermons”:
foreach ($xml->channel->item as $item) {
for ($i = 0; $i < 50; $i++) {
foreach ($item[$i]->pubDate as $date) {
#$date = str_replace(“+0000”, “”, $date);
$date = substr($date, 0, -13);
$_GET[‘newsoutput’] .= “<li>$date<br />”;
}
foreach ($item[$i]->guid as $link) {
$_GET[‘newsoutput’] .= “<a href=”$link”><strong>”;
}
foreach ($item[$i]->title as $title) {
$_GET[‘newsoutput’] .= “$title</strong></a><br />”;
}
}
}
foreach ($itunes as $item) {
for ($i = 0; $i < 50; $i++) {
foreach ($item[$i]->author as $author) {
$_GET[‘newsoutput’] .= “$author</li>”;
}
}
}
break;
# End case “sermons”
case “home”:
foreach ($xml->channel->item as $item) {
for ($i = 0; $i < 2; $i++) {
foreach ($item[$i]->pubDate as $date) {
$date = substr($date, 0, -15);
$_GET[‘newsoutput’] .= “<li><strong>$date</strong><br />”;
}
foreach ($item[$i]->guid as $link) {
$_GET[‘newsoutput’] .= “<a href=”$link”>”;
}
foreach ($item[$i]->title as $title) {
$_GET[‘newsoutput’] .= “$title</a></li>”;
}
}
}
break;
# End case “home”
} # End Switch
$_GET[‘newsoutput’] .= “</ul>”;
echo $_GET[‘newsoutput’];
}
and the call is:
[code=php]
<?php processFeed(“http://localhost/podcast.xml”,”sermons”); ?>