PHP5 and PHP4 compatibility issues

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eltower

    PHP5 and PHP4 compatibility issues

    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) -
    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

  • Martin Mandl - m2m tech support

    #2
    Re: PHP5 and PHP4 compatibility issues

    On Mar 22, 11:46 pm, "eltower" <acachin...@gma il.comwrote:
    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) -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
    Dear Adri,

    $rss->getElementsByT agName("item"); uses the a methode of the
    DOMDocument class. Thus is most likely NOT your problem with a change
    from PHP5 to PHP4.

    I assume that the class itself is written for PHP5. Or your two PHP
    setups just use different settings.

    Good luck
    Martin

    -----------------------------------------------
    online accounting on bash bases
    Online Einnahmen-Ausgaben-Rechnung

    ------------------------------------------------
    m2m server software gmbh



    Comment

    • Toby A Inkster

      #3
      Re: PHP5 and PHP4 compatibility issues

      eltower wrote:
      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.
      Google: MagpieRSS.

      --
      Toby A Inkster BSc (Hons) ARCS
      Contact Me ~ http://tobyinkster.co.uk/contact
      Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

      * = I'm getting there!

      Comment

      Working...