I have the follow code that I was given to display an rss feed. When I test it, it says "Parse error: syntax error, unexpected '[' in /home/wayneroo/public_html/bigfreebet.com/test44.php on line 6" If I take out the [] on line 6 which is: $max = [6]; /* Number results outputted */, I says no feed available, which is not right. I have tried it with lots of feeds and none work. Could someone have a look for me please <?PHP $feed = "[http://rss.paddypower.com/rss/AffiliateFootballSteamers.xml]"; $AFF_ID = "[10001227]"; $noresults = "[NO RESULTS MESSAGE]"; $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, "startElement", "endElement"); // Set the function to handle blocks of character data xml_set_character_data_handler($xml_parser, "characterData"); // 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 die(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 startElement($parser, $name, $attrs) { global $insideitem, $tag, $title, $description, $link; if ($insideitem) { $tag = $name; } elseif ($name == "ITEM") { $insideitem = true; } } function endElement($parser, $name ) { global $insideitem, $tag, $title, $description, $link, $AFF_ID, $max, $count; if ($name == "ITEM" && $count < $max) { printf("<b><a href='%s'>%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 characterData($parser, $data) { global $insideitem, $tag, $title, $description, $link; if ($insideitem) { switch ($tag) { case "TITLE": $title .= $data; break; case "DESCRIPTION": $description .= $data; break; case "LINK": $link .= $data; break; } } } ?> PHP:
As I said, I have tried that and it just says "no feeds available". I tested it with lots of working feeds to see if this was true and it says it on all of them, so its going wrong somewhere in the code.
<?PHP $feed = "http://rss.paddypower.com/rss/AffiliateFootballSteamers.xml"; $AFF_ID = "[10001227]"; $noresults = "[NO RESULTS MESSAGE]"; $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, "startElement", "endElement"); // Set the function to handle blocks of character data xml_set_character_data_handler($xml_parser, "characterData"); // 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 die(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 startElement($parser, $name, $attrs) { global $insideitem, $tag, $title, $description, $link; if ($insideitem) { $tag = $name; } elseif ($name == "ITEM") { $insideitem = true; } } function endElement($parser, $name ) { global $insideitem, $tag, $title, $description, $link, $AFF_ID, $max, $count; if ($name == "ITEM" && $count < $max) { printf("<b><a href='%s'>%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 characterData($parser, $data) { global $insideitem, $tag, $title, $description, $link; if ($insideitem) { switch ($tag) { case "TITLE": $title .= $data; break; case "DESCRIPTION": $description .= $data; break; case "LINK": $link .= $data; break; } } } ?> Seems to work
Well, I haven't tried this out, but on this line: printf("<b><a href='%s'>%s</a></b><br>", trim($link)."&AFF_ID=".$AFF_ID,htmlspecialchars(trim($title))); I would simply change it to printf("<b><a href='%s' target=\"_blank\" rel=\"nofollow\">%s</a></b><br>", trim($link)."&AFF_ID=".$AFF_ID,htmlspecialchars(trim($title)));
Thanks, it works! Do you know how to do the same in a dropdown list? It doesn't seem to work the same http://www.play-hookey.com/htmltest/ <form name="htmlMenu"> <select name="htmlSelList" size="1"> <option value="">Please select...</option> <option value="http://www.google.com">Google</option> </select> <input type="button" onClick="document.location =document.htmlMenu.htmlSelList.options [document.htmlMenu.htmlSelList.selectedIndex].value;"value="GO"> </form> PHP: