annie Posted May 30, 2004 Share Posted May 30, 2004 Here's how I pulled the RSS feed into my static HTML file: ------------- File for pulling out only the headlines and links from the RSS from Invision Power board: <?php class xItem { var $xTitle; var $xLink; var $xDescription; } // general vars $sTitle = ""; $sLink = ""; $sDescription = ""; $arItems = array(); $itemCount = 0; // ********* Start User-Defined Vars ************ // rss url goes here $uFile = "http://www.yoursite.com/forum/ssi.php?a=out&f=1,2,3,4,5&show=10&type=rss"; // descriptions (true or false) goes here // font goes here $uFont = "Verdana, Arial, Helvetica, sans-serif"; $uFontSize = "1"; // ********* End User-Defined Vars ************** function startElement($parser, $name, $attrs) { global $curTag; $curTag .= "^$name"; } function endElement($parser, $name) { global $curTag; $caret_pos = strrpos($curTag,'^'); $curTag = substr($curTag,0,$caret_pos); } function characterData($parser, $data) { global $curTag; // get the Channel information first global $sTitle, $sLink, $sDescription; $titleKey = "^RSS^CHANNEL^TITLE"; $linkKey = "^RSS^CHANNEL^LINK"; $descKey = "^RSS^CHANNEL^DESCRIPTION"; if ($curTag == $titleKey) { $sTitle = $data; } elseif ($curTag == $linkKey) { $sLink = $data; } elseif ($curTag == $descKey) { $sDescription = $data; } // now get the items global $arItems, $itemCount; $itemTitleKey = "^RSS^CHANNEL^ITEM^TITLE"; $itemLinkKey = "^RSS^CHANNEL^ITEM^LINK"; $itemDescKey = "^RSS^CHANNEL^ITEM^DESCRIPTION"; if ($curTag == $itemTitleKey) { // make new xItem $arItems[$itemCount] = new xItem(); // set new item object's properties $arItems[$itemCount]->xTitle = $data; } elseif ($curTag == $itemLinkKey) { $arItems[$itemCount]->xLink = $data; } elseif ($curTag == $itemDescKey) { $arItems[$itemCount]->xDescription = $data; // increment item counter $itemCount++; } } // main loop $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = fopen($uFile,"r"))) { die ("could not open RSS for input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); // write out the items ?> <?php for ($i=0;$i<count($arItems);$i++) { $txItem = $arItems[$i]; ?> <font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><a href = "<?php echo($txItem->xLink); ?>"><?php echo($txItem->xTitle); ?></a></font> <?php if ($bDesc) { ?> <font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><?php echo ($txItem->xDescription); ?> <?php } echo ("<br>"); } ?> --------- I then pulled apart an ordinary html file, renamed two bits, removed the starting <html> and ending </html> and uploaded the files as php Then it's time to use this script: <html> <?php include("originalfilefragment1.php"); include("simplifiedrss_script.php"); include("originalfilefragment2.php"); ?> </html> ----- And call that file with this cron job: wget -O /home/username/public_html/resultingfile.htm http://www.yoursite.com/scriptforbuildingpage.php How often you want to run the script depends on how much action the forum receives. Don't run it too often. Once every hour or more seldom? ----- One of the scripts came from here. I modified it to output less extraneous information, so it would fit more easily into my page: http://www.wirelessdevnet.com/channels/wap...mlcast_php.html Quote Link to comment Share on other sites More sharing options...
LisaJill Posted May 30, 2004 Share Posted May 30, 2004 Hey glad to see that you got that working! Just from looking at it - it requires that the page be. php or parsing php yea? Quote Link to comment Share on other sites More sharing options...
annie Posted May 30, 2004 Author Share Posted May 30, 2004 The resulting page is just straight html. I didn't want a high traffic page call out for parsing the RSS file on the fly. That was the point of the whole thing. But all the other pages included in the job are php. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.