Buying Need to programmer to help with parsing rss feed

Discussion in 'Programming' started by fadetoblack22, Apr 16, 2010.

  1. #1
    I have an rss feed and it needs some changing. I have included the code below to give you a general idea.

    1) I have an affiliate id on the links and it is currently wrong. It just needs modifying a bit.
    2) I want some nofollows put in links and css classes put in as well.
    3) Maybe also I want some links removing from the code.


    <?PHP 
    $feed = "http://rss.paddypower.com/rss/MoneyBackSpecial.xml";
    $insideitem=""; $tag=""; $title=""; $description=""; $link=""; $AFF_ID=""; $max=""; $count="";  // needs to be done for all addtional feeds
    $AFF_ID = "10001227";
    $noresults = "Check back here soon for betting money back special offers.";
    $max = 6; /* Number results outputted */ 
    $count = 0; 
    
    
    
    // Create an XML parser 
    $xml_parser = xml_parser_create(); 
    
    // Set the functions to handle opening and closing tags 
    xml_set_element_handler($xml_parser, "startElement1", "endElement1"); // needs to be done for all addtional feeds
    
    // Set the function to handle blocks of character data 
    xml_set_character_data_handler($xml_parser, "characterData1"); // needs to be done for all addtional feeds
    
    // Open the XML file for reading 
    $fp = fopen($feed ,"r") or die("No feed available."); 
    
    // Read the XML file 4KB at a time 
    while ($data = fread($fp, 4096)) { 
    
    // Parse each 4KB chunk with the XML parser created above 
    xml_parse($xml_parser, $data, feof($fp)) 
    // Handle errors in parsing 
    or sprintf("XML error: %s at line %d", 
    xml_error_string(xml_get_error_code($xml_parser)), 
    xml_get_current_line_number($xml_parser)); 
    } 
    
    // Close the XML file 
    fclose($fp); 
    
    // Free up memory used by the XML parser 
    xml_parser_free($xml_parser); 
    
    if($count == 0) { 
    echo $noresults; 
    } 
    
    function startElement1($parser, $name, $attrs) { // needs to be done for all addtional feeds
    global $insideitem, $tag, $title, $description, $link; 
    if ($insideitem) { 
    $tag = $name; 
    } elseif ($name == "ITEM") { 
    $insideitem = true; 
    } 
    } 
    function endElement1($parser, $name ) { // needs to be done for all addtional feeds
    global $insideitem, $tag, $title, $description, $link, $AFF_ID, $max, $count; 
    if ($name == "ITEM" && $count < $max ) { 
    printf("<b><a href='%s' class=\"feed_title\" target=\"_blank\" rel=\"nofollow\">%s</a></b><br>", trim($link)."&AFF_ID=".$AFF_ID,htmlspecialchars(trim($title))); 
    printf("%s<br><br>" , html_entity_decode(trim($description))); 
    $title = ""; 
    $description = ""; 
    $link = "";
    $insideitem = false; 
    $count++; 
    } 
    } 
    
    function characterData1($parser, $data) { // needs to be done for all addtional feeds
    global $insideitem, $tag, $title, $description, $link,$AFF_ID; 
    if ($insideitem) { 
    switch ($tag) { 
    case "TITLE": 
    $title .= $data; 
    break; 
    case "DESCRIPTION":
    //var_dump(strstr($data,".html"));
    if(strstr($data,".html") !== false)
    $data = str_replace(".html" , ".html?AFF_ID=".$AFF_ID , $data); 
    $description .= $data; 
    break; 
    case "LINK": 
    $link .= $data; 
    break; 
    } 
    } 
    } 
    
    ?>
    Code (markup):
     
    fadetoblack22, Apr 16, 2010 IP