after it fetching only the the FIRST RSS item - or better yet, how could I tell how many ITEMS the script should fetch before STOPPING? Extremely happy for any useful help Smiley) As you can tell, I don't know PHP that well at all.. (oh, and I'm only using the default feed assigned almost at the end of the script).
THE SCRIPT:
class RSSParser {
var $title = "";
var $link = "";
var $description = "";
var $inside_item = false;
// Add new RSS feeds using this format;
// "http://www.wherever.com/path/to/rss/" => "Display name",
var $all_rss_urls = array(
);
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
<a href='%s' target='_blank'>%s[/url]\n", trim( $this->link ), htmlspecialchars( trim( $this->title ) ) );
printf( "\t
%s
\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
function show_title( $rss_url ){
?>
<tr height="20%">
<td valign="top">
<H5>
Siste nyheter - NRK:
</H5>
</td>
</tr>
<tr height="70%">
<td valign="top">
<small><small>
<?
} // endfunc show_title
function show_list_box( $rss_url ){
?>
<?
} // end func show_list_box
} // endclass RSSParser
global $rss_url;
// Set a default feed
if( $rss_url == "" )
$rss_url = "http://www.nrk.no/nyheiter/utanriks/siste.rss";
$xml_parser = xml_parser_create();
$rss_parser = new RSSParser();
$rss_parser->show_title( $rss_url );
$rss_parser->parse_results( $xml_parser, &$rss_parser, $rss_url );
$rss_parser->show_list_box( $rss_url );
?>