africa.rss <?xml version="1.0" encoding="utf-8" ?><?xml-stylesheet type="text/xsl" href="rss-style.xsl" ?> <rss version="0.91"> <channel> <title>IOL: Africa</title> <link>http://www.iol.co.za/index.php?...truns <description>IOL: Africa</description> <language>en-gb</language> <image> <title>IOL</title> <url>http://www.iol.co.za/images/rss/iol.gif</url> <link>http://www.iol.co.za</link> </image> <item> <title>Mwanawasa won&apost pass new Zambian constitution</title> <link>http://www.iol.co.za/widgets/rss_redirect.php?...truns <description>Zambian President Levy Mwanawasa says there is not enough time to implement the country&aposs new constitution before elections in 2006.</description> <pubDate>2005-10-27 12:40:41</pubDate> </item> <item> <title>Museveni&aposs rival back in Uganda as poll nears</title> <link>http://www.iol.co.za/widgets/rss_redirect.php?...truns</link> <description>An opposition politician expected to be the main challenger to President Yoweri Museveni in the upcoming elections has ended his four years in exile.</description> <pubDate>2005-10-27 08:40:38</pubDate> </item> </channel> </rss> southafrica.rss <?xml version="1.0" encoding="utf-8" ?><?xml-stylesheet type="text/xsl" href="rss-style.xsl" ?> <rss version="0.91"> <channel> <title>IOL: South Africa</title> <link>http://www.iol.co.za/index.php?...truns</link> <description>IOL: South Africa</description> <language>en-gb</language> <image> <title>IOL</title> <url>http://www.iol.co.za/images/rss/iol.gif</url> <link>http://www.iol.co.za</link> </image> <item> <title>Train crash could have been &aposfar worse&apos</title> <link>http://www.iol.co.za/widgets/rss_redirect.php?...truns</link> <description>Frans Pritchard was fast asleep in bed on board the Trans Karoo. Suddenly he was on the floor, paralysed. For close to an hour, the 65-year-old man lay on the floor of the train, waiting for medical help - one of dozens of passengers hurt in the crash between the Blue Train and the Trans Karoo express.</description> <pubDate>2005-10-27 12:35:25</pubDate> </item> <item> <title>Hit-and-run family finds help amid despair</title> <link>http://www.iol.co.za/widgets/rss_redirect.php?...truns</link> <description>The man who has lost his mother, and then his wife and baby son in a tragic hit-and-run on a Durban highway, will be able to bury his loved ones because of kind-hearted Daily News readers.</description> <pubDate>2005-10-27 13:05:34</pubDate> </item> </channel> </rss>
$rssFeeds = array ('phpbuilder.rss');
$rssFeeds = array ('southafrica.rss','africa.rss');
Title: Train crash could have been 'far worse' Description: Frans Pritchard was fast asleep in bed on board the Trans Karoo. Suddenly he was on the floor, paralysed. For close to an hour, the 65-year-old man lay on the floor of the train, waiting for medical help - one of dozens of passengers hurt in the crash between the Blue Train and the Trans Karoo express. Link: http://www.iol.co.za/widgets/rss_redirect.php?...truns Pubdate: 2005-10-27 12:35:25 Title: Hit-and-run family finds help amid despair Description: The man who has lost his mother, and then his wife and baby son in a tragic hit-and-run on a Durban highway, will be able to bury his loved ones because of kind-hearted Daily News readers. Link: http://www.iol.co.za/widgets/rss_redirect.php?...truns Pubdate: 2005-10-27 13:05:34 Title: Mwanawasa won't pass new Zambian constitution Description: Zambian President Levy Mwanawasa says there is not enough time to implement the country's new constitution before elections in 2006. Link: http://www.iol.co.za/widgets/rss_redirect.php?...truns Pubdate: 2005-10-27 12:40:41 Title: Museveni's rival back in Uganda as poll nears Description: An opposition politician expected to be the main challenger to President Yoweri Museveni in the upcoming elections has ended his four years in exile. Link: http://www.iol.co.za/widgets/rss_redirect.php?...truns Pubdate: 2005-10-27 08:40:38
CREATE TABLE `rss_feeds` ( `id` int(11) NOT NULL auto_increment, `title` varchar(50) NOT NULL default '', `description` text NOT NULL, `link` varchar(100) NOT NULL default '', `pubdate` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`) );
function endElement($xp,$name) {
global $item,$currentElement,$title,$description,$link,$pubdate,$conn;
if ($name == 'ITEM') {
echo "<b>Title:</b> $title<br>";
echo "<b>Description:</b> $description<br>";
echo "<b>Link:</b> $link<br>";
echo "<b>Pubdate:</b> $pubdate<br><br>";
$ins_title = addslashes($title);
$ins_desc = addslashes($description);
$ins_link = addslashes($link);
$ins_pubdate = addslashes($pubdate);
$sql = "SELECT COUNT(link) as cn FROM rss_feeds WHERE link='$ins_link'";
$rs = $conn->Execute($sql);
if ($rs->fields['cn'] == 0) {
$sql = "INSERT INTO rss_feeds (title, description, link, pubdate)
VALUES('$ins_title','$ins_desc','$ins_link','$ins_pubdate')";
if (!($conn->Execute($sql))) {
print 'Error inserting: '.$conn->ErrorMsg().'<br>';
}
}
$title = '';
$description = '';
$link = '';
$pubdate = '';
$item = false;
}
}
include "db_ado_vars_test.inc.php";
//your database connection details
include "$includes_path/adodb/tohtml.inc.php";
include "$includes_path/adodb/adodb.inc.php";
$conn = &ADONewConnection('mysql');
$conn->PConnect($host,$user,$pass,$db_name);
$rssFeeds = array ('southafrica.rss','africa.rss');
mysql> SELECT * FROM rss_feeds\G *************************** 1. row *************************** id: 1 title: Train crash could have been 'far worse' description: Frans Pritchard was fast asleep in bed on board the Trans Karoo. Suddenly he was on the floor, paralysed. For close to an hour, the 65-year-old man lay on the floor of the train, waiting for medical help - one of dozens of passengers hurt in the crash between the Blue Train and the Trans Karoo express. link: http://www.iol.co.za/widgets/rss_redirect.php?...truns pubdate: 2005-10-27 12:35:25 *************************** 2. row *************************** id: 2 title: Hit-and-run family finds help amid despair description: The man who has lost his mother, and then his wife and baby son in a tragic hit-and-run on a Durban highway, will be able to bury his loved ones because of kind-hearted Daily News readers. link: http://www.iol.co.za/widgets/rss_redirect.php?...truns pubdate: 2005-10-27 13:05:34 *************************** 3. row *************************** id: 3 title: Mwanawasa won't pass new Zambian constitution description: Zambian President Levy Mwanawasa says there is not enough time to implement the country's new constitution before elections in 2006. link: http://www.iol.co.za/widgets/rss_redirect.php?...truns pubdate: 2005-10-27 12:40:41 *************************** 4. row *************************** id: 4 title: Museveni's rival back in Uganda as poll nears description: An opposition politician expected to be the main challenger to President Yoweri Museveni in the upcoming elections has ended his four years in exile. link: http://www.iol.co.za/widgets/rss_redirect.php?...truns pubdate: 2005-10-27 08:40:38 4 rows in set (0.00 sec)
//Loop through the array, reading the feeds one by one
foreach ($rssFeeds as $feed) {
readFeeds($feed);
}
$sql = "SELECT title, description, link, pubdate FROM rss_feeds
ORDER BY pubdate DESC LIMIT 100";
$rs = &$conn->Execute($sql);
while (!$rs->EOF) {
echo '<a href="'.$rs->fields['link'].'">'.
$rs->fields['title'].'</a>>'.$rs-
>fields['pubdate'].'<br>';
echo $rs->fields['description'].'<br>';
$rs->MoveNext(); // Moves to the next row
}
<?php
include "db_ado_vars_test.inc.php";
//your database connection details
include "$includes_path/adodb/tohtml.inc.php";
include "$includes_path/adodb/adodb.inc.php";
$conn = &ADONewConnection('mysql');
$conn->PConnect($host,$user,$pass,$db_name);
$rssFeeds = array ('southafrica.rss','africa.rss');
//Loop through the array, reading the feeds one by one
foreach ($rssFeeds as $feed) {
readFeeds($feed);
}
$sql = "SELECT title, description, link, pubdate FROM rss_feeds
ORDER BY pubdate DESC LIMIT 100";
$rs = &$conn->Execute($sql);
while (!$rs->EOF) {
echo ''.$rs->fields['title'].''.$rs->fields['pubdate'].'<br>';
echo $rs->fields['description'].'<br>';
$rs->MoveNext(); // Moves to the next row
}
function startElement($xp,$name,$attributes) {
global $item,$currentElement;
$currentElement = $name;
if ($currentElement == 'ITEM') {
$item = true;
}
}
function endElement($xp,$name) {
global $item,$currentElement,$title,$description,$link,$pubdate,$conn;
if ($name == 'ITEM') {
echo "Title: $title<br>";
echo "Description: $description<br>";
echo "Link: $link<br>";
echo "Pubdate: $pubdate<br><br>";
$ins_title = addslashes($title);
$ins_desc = addslashes($description);
$ins_link = addslashes($link);
$ins_pubdate = addslashes($pubdate);
$sql = "SELECT COUNT(link) as cn FROM rss_feeds WHERE
link='$ins_link'";
$rs = $conn->Execute($sql);
if ($rs->fields['cn'] == 0) {
$sql = "INSERT INTO rss_feeds (title, description, link, pubdate)
VALUES('$ins_title','$ins_desc','$ins_link','$ins_pubdate')";
if (!($conn->Execute($sql))) {
print 'Error inserting: '.$conn->ErrorMsg().'<br>';
}
}
$title = '';
$description = '';
$link = '';
$pubdate = '';
$item = false;
}
}
function characterDataHandler($xp,$data) {
global $item,$currentElement,$title,$description,$link,$pubdate;
if ($item) {
switch($currentElement) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description.=$data;
break;
case "LINK":
$link.=$data;
break;
case "PUBDATE":
$pubdate.=$data;
break;
}
}
}
function readFeeds($feed) {
$fh = fopen($feed,'r'); // open file for reading
$xp = xml_parser_create();
// Create an XML parser resource
xml_set_element_handler($xp, "startElement", "endElement");
// defines which functions to call when element started/ended
xml_set_character_data_handler($xp, "characterDataHandler");
while ($data = fread($fh, 4096)) {
if (!xml_parse($xp,$data)) {
return 'Error in the feed';
}
}
}
?>