here is part of the code I use to display various feeds from wired.com on one of my sites, this might get you started in the right direction
PHP Code:
// READ AND PARSE THE SOURCE FEED
$data = implode("", file($url));
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 1);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);
// ARRAYS TO STORE FEED INFO IN
$keys = array();
$titles = array();
$links = array();
$descriptions = array();
// EXTRACT DESIRED INFO AND STORE IN ARRAYS
foreach($values as $key=>$item) {
if($item[tag] == "TITLE") {
$titles[$key] = $item[value];
$sub = $key;
array_push($keys, $key);
}
if($item[tag] == "LINK") {
$links[$sub] = $item[value];
}
if($item[tag] == "DESCRIPTION") {
$descriptions[$sub] = $item[value];
}
if($item[tag] == "URL") {
$image = $item[value];
}
}
With the example above, you can then display the data stored in the arrays however you want on your page
Now this is by no means the only way to parse a feed, but this was the easiest solution to implement in my case.
Here is a simplified version of the code I use to display the feed data:
PHP Code:
<?
// DISPLAY NEWS ARTICLES
for($n = 2; $n < count($keys); $n++) {
$k = $keys[$n];
echo "<a href='$links[$k]' target='_blank'><b>$titles[$k]</b></a><br>";
echo "$descriptions[$k]<br><br>";
}
?>
Last edited by cmonkey : 07-08-2004 at 12:29 AM.
|