I have a feed: http://examplefeed.asp and I want it as an rss feed on my website. I want to be able to control the number of news stories that show. I found a script that does it below, but it doesn't work. I think it might be because it is php not asp. I don't know much about this. Also it doesn't let me control the number of stories shown. Can anyone help please.... <?php /* Class RSSParser: 2 October 2002 Author: Duncan Gough Overview: An RSS parser that uses PHP and freely available RSS feeds to add fresh news content to your site. Installation: Decompress the file into your webroot and include it from whichever pages on which you want to display the data, e.g; include("rss.php"); Usage: As above, just include the rss.php file from within your PHP page, and the news will appear. You should find the HTML code in the functions endElement(), show_title() and show_list_box() below, feel free to modify these to match your site. */ class RSSParser { var $title = ""; var $link = ""; var $description = false; var $inside_item = false; function startElement( $parser, $name, $attrs='' ){ global $current_tag; $current_tag = $name; if( $current_tag == "ITEM" ) $this->inside_item = true; } // endfunc startElement function endElement( $parser, $tagName, $attrs='' ){ global $current_tag; if ( $tagName == "ITEM" ) { printf( "\t<br><b><a href='%s' target='_blank'>%s</a></b>\n", trim( $this->link ), htmlspecialchars( trim( $this->title ) ) ); printf( "\t<br>%s<br>\n", htmlspecialchars( trim( $this->description ) ) ); $this->title = ""; $this->description = ""; $this->link = ""; $this->inside_item = false; } } // endfunc endElement function characterData( $parser, $data ){ global $current_tag; if( $this->inside_item ){ switch($current_tag){ case "TITLE": $this->title .= $data; break; case "DESCRIPTION": $this->description .= $data; break; case "LINK": $this->link .= $data; break; default: break; } // endswitch } // end if } // endfunc characterData function parse_results( $xml_parser, $rss_parser, $file ) { xml_set_object( $xml_parser, &$rss_parser ); xml_set_element_handler( $xml_parser, "startElement", "endElement" ); xml_set_character_data_handler( $xml_parser, "characterData" ); $fp = fopen("$file","r") or die( "Error reading XML file, $file" ); while ($data = fread($fp, 4096)) { // parse the data xml_parse( $xml_parser, $data, feof($fp) ) 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 ) ) ); } // endwhile fclose($fp); xml_parser_free( $xml_parser ); } // endfunc parse_results } // endclass RSSParser global $rss_url; // Set a default feed if( $rss_url == "" ) $rss_url = "add url here"; $xml_parser = xml_parser_create(); $rss_parser = new RSSParser(); $rss_parser->parse_results( $xml_parser, &$rss_parser, $rss_url ); ?> PHP:
If your page is ASP, you will have to find an ASP XML parser. If you're not sure what you're doing and don't want to mess with it - use my simple Feed 2 JavaScript tool. Just a couple of generated lines of code. Allows you to control the number of entries and other options as well.