I got this code from slash dot and it gives me a live news feed. What they have used is xml and php. There are php functions that can get xml data from another server.
Anyway here is my site
http://www.bohemeinteractive.com.au
and here is the script that was used
Code: Select all
<?php
/**************************************************
* *
* Name: Slashdot Headline Grabber *
* Version: 2.0 *
* Release Date: 06/08/2002 *
* Written By: Heath C. Ice *
* Nonec Technologies *
* http://www.nonec.com *
* *
***************************************************
* *
* This function will simply grab the headlines *
* from Slashdot.org and display them on your *
* website. The headlines are updated the first *
* time the page is viewed each 30 minutes. *
* *
* Setting up the headline grabber is simple. *
* First, the server your page is hosted on must *
* recognize PHP Scripts. Second, on the page *
* you want the headlines add the following to the *
* top of the page:<?php require 'slashdot.php'; \?>*
* \Then at the place in the page where you want *
* the actual headlines displayed put: *
* <?php Slashdot(); \?> *
* *
* View "slash.php" for an example on using the *
* code. *
* *
* Send any questions or comments to *
* programming@nonec.com *
* *
**************************************************/
$tags = array(
'STORY' => '<STORY>',
'STORY' => '</STORY>',
'TITLE' => '<TITLE>',
'TITLE' => '</TITLE>',
'URL' => '<URL>',
'URL' => '</URL>');
function startElement($parser, $tag, $attrs='')
{
return;
}
function endElement($parser, $tag, $attrs='')
{
global $tags, $temp, $current, $fp2;
if($tag == 'TITLE')
{
$tempї'title'] = $tempї'data'];
$tempї'data'] = "";
}else if($tag == 'URL')
{
$tempї'url'] = $tempї'data'];
$tempї'data'] = "";
}else if($tag == 'STORY')
{
$bob = "<a href='".$tempї'url']."' target='_blank'>".$tempї'title']."</a>\n";
fwrite($fp2, $bob);
$tempї'url'] = "";
$tempї'title'] = "";
$temp = '';
}
}
function Data($parser, $data)
{
global $temp;
if($data>"!" && $data<"¶") // this takes care of all of the extra tabs and other stuff that we dont want
{
$tempї'data'] .= $data;
}
}
function Slashdot()
{
global $fp2;
$begin_line = ":: ";
$end_line = "<br>";
$local_file = "slashdot.txt";
$news_file = "http://slashdot.org/slashdot.xml";
$fp = fopen($local_file, "r");
$last_time = fgets($fp, 32);
if(time()-$last_time > 1800)
{
fclose($fp);
$fp2 = fopen($local_file, "w");
fwrite($fp2, time()."\n");
$parser = xml_parser_create($type);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_set_element_handler($parser, 'startElement','endElement');
xml_set_character_data_handler($parser, 'Data');
if (!($fp = fopen($news_file, 'r')))
{
die("Failed to open $file\n");
}
while ($data = fread($fp, 10000))
{
if (!($data = utf8_encode($data)))
{
echo 'ERROR'."\n";
}
if (!xml_parse($parser, $data, feof($fp)))
{
die(sprintf( "XML error: %s at line %d\n\n",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
}
xml_parser_free($parser);
fclose($fp);
fclose($fp2);
$fp = fopen($local_file, "r");
fgets($fp, 1000);
}
while(!(feof($fp)))
{
$newsї] = fgets($fp, 1000);
}
$numlines = count($news);
for($i=0; $i<$numlines-1; $i++)
{
echo $begin_line;
echo $newsї$i];
echo $end_line;
}
fclose($fp);
}
?>
I am sorry I cant help much more. I think this kind of thing is beyond me, but maybe I have pointed you in the right direction. I think you will have to get in touch with the sites owner and see if you can use the data as well.