<?php
$term = "test";
class xItem {
var $xTitle;
var $xLink;
// var $xDescription;
}
// general vars
$sTitle = "";
$sLink = "";
$sDescription = "";
$arItems = array();
$itemCount = 0;
// ********* Start User-Defined Vars ************
// rss url goes here
// $uFile = "atom.xml";
$uFile = "http://news.google.com/news?hl=en&ned=us&ie=UTF-8&scoring=d&output=atom&q=".urlencode($term);
// descriptions (true or false) goes here
$bDesc = true;
// font goes here
$uFont = "Verdana, Arial, Helvetica, sans-serif";
$uFontSize = "2";
// ********* End User-Defined Vars **************
function startElement($parser, $name, $attrs) {
global $curTag;
$curTag .= "^$name";
}
function endElement($parser, $name) {
global $curTag;
$caret_pos = strrpos($curTag,'^');
$curTag = substr($curTag,0,$caret_pos);
}
function characterData($parser, $data) {
global $curTag; // get the Channel information first
global $sTitle, $sLink, $sDescription;
$titleKey = "^RSS^CHANNEL^TITLE";
$linkKey = "^RSS^CHANNEL^LINK";
$descKey = "^RSS^CHANNEL^DESCRIPTION";
if ($curTag == $titleKey) {
$sTitle = $data;
}
elseif ($curTag == $linkKey) {
$sLink = $data;
}
elseif ($curTag == $descKey) {
$sDescription = $data;
}
// now get the items
global $arItems, $itemCount;
$itemTitleKey = "^FEED^ENTRY^TITLE";
$itemLinkKey = "^FEED^ENTRY^LINK";
$itemDescKey = "^FEED^ENTRY^CONTENT";
if ($curTag == $itemTitleKey)
{
// make new xItem
$arItems[$itemCount] = new xItem();
$data = str_replace("&","",$data);
// set new item object's properties
$arItems[$itemCount]->xTitle = $data;
}
elseif ($curTag == $itemLinkKey) {
$data = str_replace("&","",$data);
$arItems[$itemCount]->xLink = $data;
}
elseif ($curTag == $itemDescKey) {
$patter = "!http://news.google.com(.*)=A&url=!is";
$data = preg_replace($patter, "", $data);
$arItems[$itemCount]->xDescription = $data;
// increment item counter
$itemCount++;
}
}
// main loop
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($uFile,"r"))) {
die ("could not open RSS for input");
}
while ($data = fread($fp, 4096))
{
$data = str_replace(array ('"\t", "\r", "\n"'),"",$data);
// $data = str_replace("&","",$data);
// $data = html_entity_decode($data);
$data = str_replace('<link rel="alternate" type="text/html" href="','<link>',$data);
$data = str_replace('"/>','</link>',$data);
$data = str_replace('<content type="text/html" mode="escaped">','<b11d>',$data);
$data = str_replace('</content>','</b11d>',$data);
$pattern = "!<b11d>(.*?)</b11d>!is";
preg_match_all($pattern, html_entity_decode($data), $content, PREG_SET_ORDER);
//$data = preg_replace($pattern,"TEXT\n",$data);
//echo $data;
for ($i=0; $i<count($content); $i++)
{
echo($content[$i][0]);
}
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
for ($i=0; $i<count($arItems);$i++)
{
$txItem = $arItems[$i];
// print_r($arItems[$i]);
// echo($txItem->xTitle)."<br>";
// echo($txItem->xLink)."<br><br>";
// echo($txItem->xDescription)."<br>";
}
?>