Edmond's current fof feeds
if (!function_exists('getmtime'))
{
function getmtime()
{
$a = explode (' ',microtime());
return(double) $a[0] + $a[1];
}
}
// For benchmarking
$StartTime = getmtime();
/*
example from Opml file
*/
$currentElement = "";
$link = array();
$url = "";
$title = "";
$rss = "";
function startElement($parser, $name, $attr)
{
$GLOBALS['currentElement'] = $name;
if ($name == "outline") {
$GLOBALS['url'] = $attr['htmlurl'];
$GLOBALS['title'] = $attr['title'];
$GLOBALS['rss'] = $attr['xmlUrl'];
}
} /* end startElement() */
function endElement($parser, $name)
{
$elements = array('url', 'title', 'rss');
if ($name == "outline") {
foreach ($elements as $element) {
$temp[$element] = $GLOBALS[$element];
}
$GLOBALS['link'][] = $temp;
$GLOBALS['url'] = "";
$GLOBALS['title'] = "";
$GLOBALS['rss'] = "";
}
} /* end endElement() */
function characterData($parser, $data)
{
$elements = array ('url', 'title', 'rss');
foreach ($elements as $element) {
if ($GLOBALS['currentElement'] == $element) {
$GLOBALS[$element] = $data;
}
}
}
function parseFile()
{
global $link;
/* Creating the xml parser */
$xml_parser = xml_parser_create();
/* Register the handlers */
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
/* Disabling case folding. Case-folding basically means that XML, by
* default, will send all the element names, to the parser, as
* uppercase. Since it is case-sensitive we need to disable that in
* this example. */
xml_parser_set_option ($xml_parser, XML_OPTION_CASE_FOLDING, FALSE);
/* Open the xml file and pass it to the parser in 4k chunks. Return
* an error if file cannot be opened. */
if (!($fp = fopen ("/home/ehui/rss.opml","r"))) {
die("Cannot open file.");
}
while (($data = fread($fp,4096))) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die (sprintf("XML error at line %d column %d ",
xml_get_current_line_number($xml_parser),
xml_get_current_column_number($xml_parser)));
}
}
/* Finish ! we free the parser and returns the array */
xml_parser_free($xml_parser);
return $link;
}
$result= Parsefile();
foreach ($result as $arr) {
echo "- " . $arr["title"] . " -- rss
";
}
/*
// No, this implementation isn't pretty... should use XML to parse the OPML so it's more robust....
$lines = file('/home/ehui/rss.opml');
foreach ($lines as $line_num => $line) {
$out = explode("\"",$line);
if (preg_match("/htmlurl/", $out[0]))
$url = $out[1];
if (preg_match("/title/", $out[0]))
$title = $out[1];
if (preg_match("/xmlUrl/", $out[0]))
echo "- $title -- rss
";
}
*/
?>
$total = getmtime() - $StartTime;
printf("This list is generated in %.3f sec.", $total);
?>