Home | Scripts | Tutorials | Books | Hosting | Forums | Links|

Navigation:

Home
Source code
Tutorials
RSS feeds
Articles
Books
Software
Downloads
Hosting
manuals
Forums
Script directory
Training
Our Links

ADD TO Progged Progged
ADD TO DEL.ICIO.US Del.icio.
ADD TO DIGG Digg
ADD TO FURL Furl
ADD TO NEWSVINE Newsvine
ADD TO NETSCAPE Netscape
ADD TO REDDIT Reddit
ADD TO STUMBLEUPON StumbleUpon
ADD TO TECHNORATI FAVORITES Technorati
ADD TO SQUIDOO Squidoo
ADD TO WINDOWS LIVE Windows Live
ADD TO YAHOO MYWEB Yahoo MyWeb
ADD TO ASK Ask
ADD TO GOOGLE Google
ADD TO MAGNOLIA Magnolia
ADD TO SPURL Spurl



 
 

SPONSORS



 
 

Retrieve news from Linux Today


I would love to take the credit for this script but it is fact based on one I found in Beginning PHP 4 from wrox , which is an excellent PHP book.

Here is the code

<?php
if( ! ($fp = fopen("http://linuxtoday.com/backend/biglt.rss" , "r" )) )
die("Couldn't open xml file!");
$item_counter = 0;
$in_item_tag = 0;
$lintod_current_tag_state = '';
$lintod_headline_data = array();
function startElementHandler( $parser, $element_name, $element_attribs )
{
global $item_counter;
global $in_item_tag;
global $lintod_current_tag_state;
global $lintod_headline_data;
if( $element_name == "ITEM" )
{
$in_item_tag = 1;
}
if( $in_item_tag == 1 )
{
$lintod_current_tag_state = $element_name;
}
else
{
$lintod_current_tag_state = '';
}
}
function endElementHandler( $parser, $element_name )
{
global $item_counter;
global $in_item_tag;
global $lintod_current_tag_state;
global $lintod_headline_data;
$lintod_current_tag_state = '';
if( $element_name == "ITEM" )
{
$item_counter++;
$in_item_tag = 0;
}
}
function characterDataHandler( $parser , $data )
{
global $item_counter;
global $in_item_tag;
global $lintod_current_tag_state;
global $lintod_headline_data;
if( $lintod_current_tag_state == '' || $in_item_tag == 0 )
return;
if( $lintod_current_tag_state == "TITLE" ) {
$lintod_headline_data[$item_counter]["title"] = $data;
}
if( $lintod_current_tag_state == "LINK" ) {
$lintod_headline_data[$item_counter]["link"] = $data;
}
if( $lintod_current_tag_state == "DESCRIPTION" ) {
$lintod_headline_data[$item_counter]["description"] = $data;
}
}
if( !($xml_parser = xml_parser_create()) )
die("Couldn't create XML parser!");

xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler");
xml_set_character_data_handler( $xml_parser , "characterDataHandler" );
while( $data = fread($fp, 4096) )
{
if( !xml_parse($xml_parser, $data, feof($fp)) )
{
break; // get out of while loop if we're done with the file
}
}
xml_parser_free($xml_parser);
?>
<HTML>
<HEAD>
<TITLE>linux today news</TITLE>
</HEAD>

<BODY BGCOLOR="#ffffff">

<H3>Linux today news</H3>
<BR>
<?php

for( $i=0 ; $i < $item_counter ; ++$i )
{
printf("<A HREF=\"%s\">%s</a> - %s<br>\n" , $lintod_headline_data[$i]["link"] ,
$lintod_headline_data[$i]["title"] ,
$lintod_headline_data[$i]["description"] );
}

?>

</BODY>
</HTML>

Click here to see the example