adactio.com/journal/1202 has a very interesting PHP script which
gathers RSS data from various feeds and prints them in an HTML table.
He calls this a lifestream.
Anyways, unfortunately, my knowledge of PHP is rather limited - I'd
rather work with a stylesheet. It turns out that my local machine has
PHP5, and the script works flawlessly. However, Bluehost, my hosting
provider, has PHP 4.4.4. As a result, I'm getting a lot of exceptions
thrown around. I think I figured out my way around the
getElementsByTa gName(), which should be get_elements_by _tagname() in
PHP4, but I'm still getting heavy exceptions. I also googled and found
that the date_default_ti mezone_set() function isn't supported in PHP4
either.
I'd appreciate it greatly if anyone could point out where the
incompatibiliti es are - even if there's a better way of doing this RSS
gathering, I'd just like to see anyway for educational purposes.
My PHP source is the following (I've left out the HTML surrounding
it):
<?php
date_default_ti mezone_set("Eur ope/Paris");
$feeds = array(
"feed1" ="http://...",
"feed2" ="http://...",
"feed3" ="http://...",
"feed4" ="http://..."
);
$details = array("title"," link");
$list = array();
$rss = new DOMDocument();
foreach ($feeds as $name =$feed) {
$rss -load($feed);
$items = $rss -getElementsByTa gName("item");
foreach ($items as $item) {
if ($item -getElementsByTa gName("pubDate" ) -item(0)) {
$date = $item -getElementsByTa gName("pubDate" ) ->
item(0) -nodeValue;
} else {
$date = $item -getElementsByTa gName("date") -item(0) -
}
$date = strtotime(subst r($date,0,25));
$list[$date]["name"] = $name;
foreach ($details as $detail) {
$list[$date][$detail] = $item ->
getElementsByTa gName($detail) -item(0) -nodeValue;
}
}
}
krsort($list);
$day = "";
foreach ($list as $timestamp =$item) {
$this_day = date("F jS",$timestamp) ;
if ($day != $this_day) {
echo "</tbody>\n";
echo "<thead>\n" ;
echo "<tr>\n";
echo "<th colspan=\"3\">" ;
echo $this_day;
echo "</th>\n";
echo "</tr>\n";
echo "</thead>\n";
echo "<tbody>\n" ;
$day = $this_day;
}
echo "<tr class=\"vevent_ ";
echo $item["name"];
echo "\">\n";
echo "<th>";
echo "<abbr class=\"dtstart \" title=\"";
echo date("c",$times tamp);
echo "\">";
echo date("g:ia",$ti mestamp);
echo "</abbr>";
echo "</th>\n";
echo "<td>";
echo "<a class=\"url_sum mary\" href=\"";
echo $item["link"];
echo "\">";
echo $item["title"];
echo "</a>";
echo "</td>\n";
echo "<td class=\"icon\"> ";
echo "<img src=\"images/";
echo $item["name"];
echo ".gif\" alt=\"";
echo $item["name"];
echo "\" />";
echo "</td>\n";
echo "</tr>\n";
}
?>
Many thanks,
Adri
gathers RSS data from various feeds and prints them in an HTML table.
He calls this a lifestream.
Anyways, unfortunately, my knowledge of PHP is rather limited - I'd
rather work with a stylesheet. It turns out that my local machine has
PHP5, and the script works flawlessly. However, Bluehost, my hosting
provider, has PHP 4.4.4. As a result, I'm getting a lot of exceptions
thrown around. I think I figured out my way around the
getElementsByTa gName(), which should be get_elements_by _tagname() in
PHP4, but I'm still getting heavy exceptions. I also googled and found
that the date_default_ti mezone_set() function isn't supported in PHP4
either.
I'd appreciate it greatly if anyone could point out where the
incompatibiliti es are - even if there's a better way of doing this RSS
gathering, I'd just like to see anyway for educational purposes.
My PHP source is the following (I've left out the HTML surrounding
it):
<?php
date_default_ti mezone_set("Eur ope/Paris");
$feeds = array(
"feed1" ="http://...",
"feed2" ="http://...",
"feed3" ="http://...",
"feed4" ="http://..."
);
$details = array("title"," link");
$list = array();
$rss = new DOMDocument();
foreach ($feeds as $name =$feed) {
$rss -load($feed);
$items = $rss -getElementsByTa gName("item");
foreach ($items as $item) {
if ($item -getElementsByTa gName("pubDate" ) -item(0)) {
$date = $item -getElementsByTa gName("pubDate" ) ->
item(0) -nodeValue;
} else {
$date = $item -getElementsByTa gName("date") -item(0) -
nodeValue;
$date = strtotime(subst r($date,0,25));
$list[$date]["name"] = $name;
foreach ($details as $detail) {
$list[$date][$detail] = $item ->
getElementsByTa gName($detail) -item(0) -nodeValue;
}
}
}
krsort($list);
$day = "";
foreach ($list as $timestamp =$item) {
$this_day = date("F jS",$timestamp) ;
if ($day != $this_day) {
echo "</tbody>\n";
echo "<thead>\n" ;
echo "<tr>\n";
echo "<th colspan=\"3\">" ;
echo $this_day;
echo "</th>\n";
echo "</tr>\n";
echo "</thead>\n";
echo "<tbody>\n" ;
$day = $this_day;
}
echo "<tr class=\"vevent_ ";
echo $item["name"];
echo "\">\n";
echo "<th>";
echo "<abbr class=\"dtstart \" title=\"";
echo date("c",$times tamp);
echo "\">";
echo date("g:ia",$ti mestamp);
echo "</abbr>";
echo "</th>\n";
echo "<td>";
echo "<a class=\"url_sum mary\" href=\"";
echo $item["link"];
echo "\">";
echo $item["title"];
echo "</a>";
echo "</td>\n";
echo "<td class=\"icon\"> ";
echo "<img src=\"images/";
echo $item["name"];
echo ".gif\" alt=\"";
echo $item["name"];
echo "\" />";
echo "</td>\n";
echo "</tr>\n";
}
?>
Many thanks,
Adri
Comment