Thread: Reading the VDC RSS File In PHP

View Single Post

  #7 (permalink)  

Old 02-19-2005, 04:09 PM

PHP Code:
// #################### RANDOM TUTORIAL XML SOCKET ###################
class xItem {
  var 
$xTitle;
  var 
$xLink;
  var 
$xDescription;
  var 
$xImg;
}
// general vars
$sTitle "";
$sLink "";
$sDescription "";
$xImg "";
$arItems = array();
$itemCount 0;
// ********* Start User-Defined Vars ************
// rss url goes here
$uFile 'rss.xml';
// descriptions (true or false) goes here
$bDesc true;
// ********* 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";
  
$itemImgKey "^RSS^CHANNEL^ITEM^IMAGE";

  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;
  }
  elseif (
$curTag == $itemImgKey) {
    
$arItems[$itemCount]->xImg $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($fp4096)) {
  if (!
xml_parse($xml_parser$datafeof($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
srand((float) microtime() * 10000000); 
$rand_keys array_rand($arItems5);
for (
$i=0;$i<count($rand_keys);$i++) {
$txItem $arItems["$rand_keys[$i]"];
$randtut['tutlink'] = $txItem->xLink;
$randtut['xTitle'] = $txItem->xTitle;
$randtut['image'] = $txItem->xImg;
$randtut['Description'] = $txItem->xDescription;
eval(
"\$home[randtut] .= \"".fetch_template('vbindex_randtut')."\";");

theres the code
__________________
Audi Videos | MySpace Layouts | About Me | Kid Sniffles
[ reply ]
missionsix

missionsix is offline http://patandrew.com/

missionsix's Avatar

Join Date: Feb 2004

Location: under you.

Posts: 4,875

Send a message via AIM to missionsix Send a message via MSN to missionsix