Jump to content

Include A Forum Rss Feed Into A Static Html Page


Recommended Posts

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:




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";


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";



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





// 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)));






// write out the items




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>


if ($bDesc) {


<font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><?php echo ($txItem->xDescription); ?>



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:

















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:


Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...