Hello,
I recently started coding in PHP, version 5 to be exact, and for my second project I learned that our server only has version 4.3 installed. I can't seem to find the right article/resource/tutorial to show me how to change code from 5 to 4.

All I am doing is loading an XML file and outputting the results in a list; here is version 5

<?php
$xmlFile = "File.xml";
$doc = new DOMDocument();
$doc->load($xmlFile);
?>
<html>
<head>
</head>
<body>
<div id="bkgroundContainer">
<div id="contentContainer">
<?php

# WRITE MENU
echo "<ol class=\"menu\">\n";
$element = $doc->getElementsByTagName( "btn" );
foreach( $element as $btn )
{
    $names = $btn->getElementsByTagName( "name" );
    $urls = $btn->getElementsByTagName( "url" );

$name = $names->item(0)->nodeValue;
$url = $urls->item(0)->nodeValue;

echo "<li><a href=\"" . $url . "\">" . $name . "</a></li>\n";
}
echo "</ol>\n";

# WRITE FEEDS
echo "<ol class=\"feeds\">\n";
$element = $doc->getElementsByTagName( "content" );
foreach( $element as $feed )
{
    $heads = $feed->getElementsByTagName( "head" );
    $bodys = $feed->getElementsByTagName( "body" );
    $urls = $feed->getElementsByTagName( "url" );

$head = $heads->item(0)->nodeValue;
$body = $bodys->item(0)->nodeValue;
$url = $urls->item(0)->nodeValue;

echo "<li><a href=\"" . $url . "\"><span class=\"bold\">" . $head . "</span><br/>" . $body . "</a></li>\n";
}
echo "</ol>\n";

?>
</div>
</div>
</body>
</html>

Can you point me how I re-write this in version 4?

    Hi NogDog,

    Question for you, I've been reading the link you sent, searching this forum for other examples and even looked outside like kirupa.com and have notice that no one is using any built-in methods of the DOM XML class. Should I use this method? http://www.kirupa.com/web/xml_php_parse_beginner.htm

    It just seems that PHP5 made it a lot easier to work with XML or i'm still too new to PHP4 to see how it works.

      Hi,
      I looked through several contributions to the help files and it prompted me to do the following; which produces the same result as PHP5

      # WRITE MENU
      echo "<ol class=\"menu\">\n";
      $element = $root->get_elements_by_tagname('btn');
      foreach( $element as $btn )
      {
          $names = $btn->get_elements_by_tagname( "name" );
      	foreach($names as $temp1) {
      		$name = $temp1->get_content();
      	}
      
      $urls = $btn->get_elements_by_tagname( "url" );
      foreach($urls as $temp2) {
         $url = $temp2->get_content();
      }
      
         echo "<li><a href=\"" . $url . "\">" . $name . "</a></li>\n";
      }
      echo "</ol>\n";

        It just seems that PHP5 made it a lot easier to work with XML or i'm still too new to PHP4 to see how it works.

        I found SimpleXML to be very easy to use, but it is only available in PHP 5.

        I looked through several contributions to the help files and it prompted me to do the following; which produces the same result as PHP5

        Good to see that you have found a solution, but I note that official support for PHP 4 by the developers of PHP ended almost three months ago, though updates to fix security issues might still be made, but even that will end in just over four months.

        Consequently, it may be even better for you to pressure your server administrator to upgrade to PHP 5, or at least support PHP 5.

          Write a Reply...