Reply to PHP5 and PHP4 compatibility issues

Your name:

Reply:


Posted by eltower on 03/22/07 22:46

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
getElementsByTagName(), 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_timezone_set() function isn't supported in PHP4
either.

I'd appreciate it greatly if anyone could point out where the
incompatibilities 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_timezone_set("Europe/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 -> getElementsByTagName("item");

foreach ($items as $item) {

if ($item -> getElementsByTagName("pubDate") -> item(0)) {
$date = $item -> getElementsByTagName("pubDate") ->
item(0) -> nodeValue;
} else {
$date = $item -> getElementsByTagName("date") -> item(0) -
> nodeValue;
}
$date = strtotime(substr($date,0,25));

$list[$date]["name"] = $name;

foreach ($details as $detail) {

$list[$date][$detail] = $item ->
getElementsByTagName($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",$timestamp);
echo "\">";
echo date("g:ia",$timestamp);
echo "</abbr>";
echo "</th>\n";
echo "<td>";
echo "<a class=\"url_summary\" 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация