Unregistered Avatar

Reply

Reading the VDC RSS File In PHP


 
LinkBack Thread Tools Display Modes

  #1 (permalink)  

Old 02-18-2005, 08:04 PM

Reading the VDC RSS File In PHP

Well I've spent an hour on this script hoping to make an RSS reader just for VDC (here) but was unfruitful at the fact that I could not find the actual file in the first place, however, Heres the class, if anyone wants to make something of it, go ahead. Or maybe some help locating the file?

Basically what I did was opened the RSS file with fopen, read the file to its full length (since there is only 25 items in the RSS file to begin with) and then just had the class take care of the rest. Then later used preg_match_all and regular expressions (very simple ones) to get the contents, used for- statements with $i to output the tables with the images and other things based on the configuration at the top of the file. However, I've spent almost 30 minutes trying to figure out why it was not working, I've been moving stuff around and then realized that I had used the @-command to surpress errors when opening and reading the file, so I had no idea that the script wasn't reading the file in the first place.

What did I do wrong? I tried a much more simple version just trying to opent he RSS file and I got an error at that, so Im pretty sure the script just isn't working because of that, but I wouldn't know.

Anyways, if you would like to use this for a different RSS file, feel free too, just edit the regular expressions on lines 150-160.
Attached Files
File Type: zip vdcorerss.zip (3.2 KB, 2 views)

Last edited by borednerd : 02-18-2005 at 08:37 PM.

borednerd is offline registered.

borednerd's Avatar

Join Date: Feb 2005

Posts: 31

  #2 (permalink)  

Old 02-19-2005, 11:00 AM

hmm ill take a look. I can give you the code i used for the front page if you want.
__________________
Audi Videos | MySpace Layouts | About Me

missionsix is offline loves you.

missionsix's Avatar

Join Date: Feb 2004

Location: under you.

Posts: 4,774

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

  #3 (permalink)  

Old 02-19-2005, 03:14 PM

Yeah that would be nice..Ive been having trouble locating the file ..whenever I tried to open or read it, I always end up with an error.

borednerd is offline registered.

borednerd's Avatar

Join Date: Feb 2005

Posts: 31

  #4 (permalink)  

Old 02-19-2005, 03:31 PM

have you downloaded it and tried doing it locally yet? and hold on i'll upload the code in a sec.
__________________
Audi Videos | MySpace Layouts | About Me

missionsix is offline loves you.

missionsix's Avatar

Join Date: Feb 2004

Location: under you.

Posts: 4,774

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

  #5 (permalink)  

Old 02-19-2005, 04:00 PM

Yeah, I downloaded, but had trouble finding it again..whats wrong with me? But then I uploaded to same dir as the file I was testing, did ./rss.xml in the fopen variable, and it worked. Now im working on parsing the contents, turns out I did it wrong after all.

borednerd is offline registered.

borednerd's Avatar

Join Date: Feb 2005

Posts: 31

  #6 (permalink)  

Old 02-19-2005, 04:07 PM

sweet. If you still want my source tell me and i'll find it... gotta redownload the file.
__________________
Audi Videos | MySpace Layouts | About Me

missionsix is offline loves you.

missionsix's Avatar

Join Date: Feb 2004

Location: under you.

Posts: 4,774

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

  #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

missionsix is offline loves you.

missionsix's Avatar

Join Date: Feb 2004

Location: under you.

Posts: 4,774

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

  #8 (permalink)  

Old 02-19-2005, 04:21 PM

Ah yes, see I wasn't doing that. I was using regular expressions that really...really pissed me off later. I was even playing around and got this expression for reading items:
Code:
([- ]{2})([<>]{1})([a-zA-Z]{4})([<>]{1})\n([ ]{1,2})([<>]{1})([a-zA-Z]{5})([<>]{1})([a-zA-Z](.*))([<>/]{1})([ ]{1,2})\n([ ]{2})([<>]{1})([a-zA-Z]{4})([<>]{1})((.*))([>/<]{2})([a-zA-Z]{4})([<>]{1})([ ]{1,2})\n([ ]{1,2})([<>]{1})([a-zA-Z]{11})([<>]{1})((.*))([</>]{2})([a-zA-Z]{11})([<> ]{2})\n(([ ]{2}))(([<>a-zA-Z]{7}))((.*))(([</>a-zA-Z]{7}))(([ ]{1,2}))\n([ a-zA-Z<>]{13})((.*))([</>a-zA-Z]{12})([ ]{1})\n([ ]{2})([a-zA-Z:;<>]{12})((.*))([a-zA-Z:/;<>]{13})([ ]{1})\n([ ]{2})([a-zA-Z:;<>]{9})([0-9]{4})([a-zA-Z:/;<>]{10})([ ]{1})\n([ ]{2})([<>/;:a-zA-Z0-9]{7})
Which I decided against cuase it hurts my eyes...but ill try it your way if I can find the file on your server again

Thanks for the code, Ill update when i get it to work.

borednerd is offline registered.

borednerd's Avatar

Join Date: Feb 2005

Posts: 31

  #9 (permalink)  

Old 02-19-2005, 04:45 PM

damn thats a length expression. Very thorough though.
__________________
Audi Videos | MySpace Layouts | About Me

missionsix is offline loves you.

missionsix's Avatar

Join Date: Feb 2004

Location: under you.

Posts: 4,774

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



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP tutorial request Thread: missionsix Website Design 29 06-03-2007 02:09 PM
El Diablo de Lag! The Anti-Bob The VOID! 5 05-01-2006 09:42 PM
View raw PHP source DARTAGNAN Request Content 3 12-09-2005 01:56 PM
Insert text with PHP syntax highlighting Dr. de Seis The VOID! 8 04-06-2005 10:38 PM
Hmm some help with buttons and saving UAGFX 3D Art and Animation 1 07-11-2004 02:21 PM


All times are GMT -7. The time now is 04:46 AM.