All pastes #278537 Raw Edit

Untitled

public text v1 · immutable
·published 2006-12-14 04:25 UTC
rendered paste body
<?php
// Extracts content from XML tag

function GetElementByName ($xml, $start, $end) {

   global $pos;
   $startpos = strpos($xml, $start);
   if ($startpos === false) {
       return false;
   }
   $endpos = strpos($xml, $end);
   $endpos = $endpos+strlen($end);   
   $pos = $endpos;
   $endpos = $endpos-$startpos;
   $endpos = $endpos - strlen($end);
   $tag = substr ($xml, $startpos, $endpos);
   $tag = substr ($tag, strlen($start));

   return $tag;

}

// Open and read xml file. You can replace this with your xml data.

$file = "http://rss.weather.com.au/sa/adelaide";
$pos = 0;
$Nodes = array();

if (!($fp = fopen($file, "r"))) {
   die("could not open XML input");
}
while ($getline = fread($fp, 4096)) {
   $data = $data . $getline;
}

$count = 0;
$pos = 0;

// Goes throw XML file and creates an array of all <XML_TAG> tags.
while ($node = GetElementByName($data, "<item>", "</item>")) {
   $Nodes[$count] = $node;
   $count++;
   $data = substr($data, $pos);
}
?>


THEN THIS


<?php { ?>
<?php
$title = GetElementByName($Nodes[0], "<title>", "</title>");
$desc = str_replace( array('<![CDATA[', ']]>'), '',GetElementByName($Nodes[0], "<description>", "</description>"));
$pubDate = GetElementByName($Nodes[0], "<pubDate>", "</pubDate>");
?>
<div class="sub_heading">
<?php echo $title; ?></div>
<div class="body_copy"><p><?php echo $desc; ?></p></div>
<div class="body_copy"><p><?php echo $pubDate; ?></p></div>
<?php } ?>						  </td>
                          <td>  
<?php { ?>
<?php
$title = GetElementByName($Nodes[1], "<title>", "</title>");
$desc = str_replace( array('<![CDATA[', ']]>'), '',GetElementByName($Nodes[1], "<description>", "</description>"));
$pubDate = GetElementByName($Nodes[1], "<pubDate>", "</pubDate>");
?>
<div class="sub_heading">
<?php echo $title; ?></div>
<div class="body_copy"><?php echo $desc; ?></div>
<?php } ?>