DOM in PHP5/PHP4

liunx

Guest
... I can't get my webserver upgraded? How would I do the same thing in php4?... I can't get my webserver upgraded? How would I do the same thing in php4?
Hint: In PHP 5 these two lines:

$filelocs = $value->getElementsByTagName("fileloc");
$fileloc = $filelocs->item(0)->nodeValue;
could be written as one:

$fileloc = $value->getElementsByTagName("fileloc")->item(0)->nodeValue;

Another hint that doubles as a tip: you don't need to use a different variable every time.Yea I have to admit I was being a little silly with that question. I wasn't really being clear. I have a script that aggregates rss feeds for an index to my site. I copied this script from an acquaintance. I think he wrote it for php5 and the DOMDocument APIs are all different for 4. And I can't seem to find good documentation for the API version my server is using. Neither the 4 or 5 api documentation matches the errors I'm getting for the DOMDocument constructor. For php5 the constructor requires no aruguments and has a "load" method to load pages from http requests. PHP 4 documentation says that the DOMDocument object takes two string arguments for "version" and "encoding". The version on my server appears to want a string that contains the xml code because it is present an error that says expect "<" tag.

Here is the script. Any advice on porting it to php4 or help with figuring out what version is running on my hosting companies web server would be greatly appreciated.

<table class="hcalendar">
<tbody>
<?php

/* date_default_timezone_set("Europe/London"); */

$feeds = array(
"adactio" => "http://adactio.com/journal/rss",
"domscripting" => "http://domscripting.com/blog/rss",
"link" => "http://del.icio.us/rss/adactio",
"picture" => "http://www.flickr.com/services/feeds/photos_public.gne?id=74105777@N00&format=rss_200",
"song" => "http://ws.audioscrobbler.com/1.0/user/adactio/recenttracks.rss",
"message" => "http://twitter.com/statuses/user_timeline/11250.rss"
);

$details = array("title","link");

$list = array();

$rss = new DOMDocument();

foreach ($feeds as $name => $feed) {

/* $rss -> load($feed); */
$rss = new DOMDocument();

$items = $rss -> get_elements_by_tagname("item");

foreach ($items as $item) {

$foo = $item -> get_elements_by_tagname("pubDate");
if ($foo -> item(0)) {

$foo = $item -> get_elements_by_tagname("pubDate");
$bar = $foo -> item(0);
$date = $bar -> nodeValue;

} else {

$foo = $item -> get_elements_by_tagname("date");
$bar = $foo -> item(0);
$date = $bar -> nodeValue;
}
$date = strtotime(substr($date,0,25));

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

foreach ($details as $detail) {

$foo = $item -> get_elements_by_tagname($detail);
$bar = $foo -> item(0);
$list[$date][$detail] = $bar -> 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=http://www.phpbuilder.com/board/archive/index.php/\"";
echo $item["link"];
echo "\">";
echo $item["title"];
echo "</a>";
echo "</td>\n";
echo "<td>";
echo "<img src=http://www.phpbuilder.com/board/archive/index.php/\"images/";
echo $item["name"];
echo ".gif\" alt=\"";
echo $item["name"];
echo "\" />";
echo "</td>\n";
echo "</tr>\n";

}

?>
</tbody>
</table>Ah, so it's a totally different problem and hence ought to be in a totally different thread. Probably a different forum, in fact.

PHP 4 and PHP 5 do not use the same DOM extension. PHP 5 uses DOM and PHP 4 used DOMXML. Stuff written for one will not run in the other.

You might also want to use
PHP:
...
tags around your PHP code or people won't bother trying to read it.
 
Back
Top