A tu znaleziony przezemnie parser RSSów i ładnie przerobiony[php:1:116733c485]<?php
if ( IsSet( $_GET['RSS'] ) && ereg("http://", $_GET['RSS'] ) )
{
$rss_file = $_GET['RSS'];
}
else
{
$rss_file = 'http://www.php.net/news.rss';
}
$rss_files = array(
'http://www.php.net/news.rss',
'http://www.sitepoint.com/rss.php',
'http://www.devshed.com/Other_Stuff/Syndication/devshedrss.xml'
// '',
);
print '<p>Inne pliki RSS:<br />';
foreach ( $rss_files AS $_rss_file )
{
print '&&&+ <a href="?RSS=' . $_rss_file . '">' . $_rss_file . '</a><br />' . "n";
}
print '</p>- - - - - - - - - - - -<br />';
class RSSParser
{
var $insideitem = false;
var $tag = "";
var $title = "";
var $description = "";
var $link = "";
var $image = "";
var $date = "";
function RSSParser( $rss_file )
{
$xml_parser = xml_parser_create();
xml_set_object( $xml_parser, &$this );
xml_set_element_handler( $xml_parser, "startElement", "endElement" );
xml_set_character_data_handler( $xml_parser, "characterData" );
$fp = fopen( $rss_file, "r" )
or die( "Error reading RSS data." );
while ( $data = fread( $fp, 4096 ) )
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 ) ) );
fclose( $fp );
xml_parser_free( $xml_parser );
} // end function 'RSSParser'
function startElement( $parser, $tagName, $attrs )
{
if ( $this->insideitem )
{
$this->tag = $tagName;
}
else if ( $tagName == "ITEM" )
{
$this->insideitem = true;
} // end if... else if...
} // end function 'startElement'
function endElement( $parser, $tagName )
{
if ( $tagName == "ITEM" )
{
// Printing image if exists
if ( !( empty( $this->image ) ) )
{
$size = GetImageSize( $this->image );
printf( "<img src="%s" width="%s" height="%s" border="0" align="left" valign="top">",
trim( $this->image ), $size[0], $size[1] );
$size = '';
} // end if...
// Printing date
if ( !( empty( $this->date ) ) )
{
printf( "<p><b>%s</b> | ",
trim( $this->date ) );
}
else
{
print '<p>';
} // end if... else...
// Printing link
printf( "<b><a href="%s" target="_blank">%s</a></b></p>",
trim( $this->link ), htmlspecialchars( trim( $this->title ) ) );
// Printing description
printf( "<p>%s</p>",
htmlspecialchars( trim( $this->description ) ) );
$this->title = "";
$this->description = "";
$this->link = "";
$this->image = "";
$this->date = "";
$this->insideitem = false;
} // end if...
} // end function 'endElement'
function characterData( $parser, $data )
{
if ( $this->insideitem )
{
switch ( $this->tag )
{
case "TITLE":
$this->title .= $data;
break;
case "DESCRIPTION":
$this->description .= $data;
break;
case "LINK":
$this->link .= $data;
break;
case "IMAGE":
$this->image .= $data;
break;
case "DATE":
$this->date .= $data;
break;
case "DC:DATE":
$this->date .= $data;
break;
} // end switch
} // end if...
} // end function 'characterData'
} // end class 'RSSParser'
$ParseRSS = new RSSParser( $rss_file );
?>[/php:1:116733c485]
Demo:
http://dev.webcenter.net.pl/RSSParser.php