Aaah I've been looking for this, I'm also on the same lines as Triky was with duplicating the results, not sure how to solve it even though you said that I need to include the output before re-using the code again.
What I have so far is this:
PHP Code:
<?php
$rss2_art_file = 'http://localhost:41648/forums/external.php?type=RSS2&forumids=8';
$rss2_games_file = 'http://localhost:41648/forums/external.php?type=RSS2&forumids=5';
$is_item = false;
$tag = '';
$title = '';
$description = '';
$link = '';
$date = '';
$author = '';
function character_data($parser, $data) {
global $is_item, $tag, $title, $description, $link, $date, $author;
if ($is_item) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
$link .= $data;
break;
case "PUBDATE":
$date .= $data;
break;
case "AUTHOR":
$author .= $data;
break;
}
}
}
function begin_element($parser, $name) {
global $is_item, $tag;
if ($is_item) {
$tag = $name;
} else if ($name == "ITEM") {
$is_item = true;
}
}
function end_element($parser, $name) {
global $is_item, $title, $description, $link, $date, $author, $rss2_art, $rss2_games;
if ($name == "ITEM") {
$rss2_art .= "<b><a href='" . trim($link) . "'>" . htmlspecialchars(trim($title)) . "</a></b> - " . htmlspecialchars(trim($date)) . "<br>";
$rss2_games .= "<b><a href='" . trim($link) . "'>" . htmlspecialchars(trim($title)) . "</a></b> - " . htmlspecialchars(trim($date)) . "<br>";
$title = "";
$description = "";
$link = "";
$date = "";
$author = "";
$is_item = false;
}
}
$parser = xml_parser_create();
xml_set_element_handler($parser, "begin_element", "end_element");
xml_set_character_data_handler($parser, "character_data");
$fp_art = fopen($rss2_art_file,"r");
$fp_games = fopen($rss2_games_file,"r");
while ($data = fread($fp_art, 4096)) {
xml_parse($parser, $data, feof($fp_art));
}
while ($data = fread($fp_games, 4096)) {
xml_parse($parser, $data, feof($fp_games));
}
fclose($fp_art);
fclose($fp_games);
xml_parser_free($parser);
?>
That is in a separate file required once into the page and have it echoed out, but like Triky had, I have a duplicate.