Kyberia v1.0
[mirrors/Kyberia-bloodline.git] / boxiky / nanotech.rss
... / ...
CommitLineData
1<?php
2$filename="http://www.nanodot.org/nanodot.rss";
3class RSSParser {
4
5 var $insideitem = false;
6 var $tag = "";
7 var $title = "";
8 var $description = "";
9 var $link = "";
10
11 function startElement($parser, $tagName, $attrs) {
12 if ($this->insideitem) {
13 $this->tag = $tagName;
14 } elseif ($tagName == "ITEM") {
15 $this->insideitem = true;
16 }
17 }
18
19 function endElement($parser, $tagName) {
20 if ($tagName == "ITEM") {
21 printf("<dt><b><a href='%s'>%s</a></b></dt>",
22
23trim($this->link),htmlspecialchars(trim($this->title)));
24
25printf("<dd>%s</dd>",htmlspecialchars(trim($this->description)));
26 $this->title = "";
27 $this->description = "";
28 $this->link = "";
29 $this->insideitem = false;
30 }
31 }
32
33 function characterData($parser, $data) {
34 if ($this->insideitem) {
35 switch ($this->tag) {
36 case "TITLE":
37 $this->title .= $data;
38 break;
39 case "DESCRIPTION":
40 $this->description .= $data;
41 break;
42 case "LINK":
43 $this->link .= $data;
44 break;
45 }
46 }
47 }
48}
49
50$xml_parser = xml_parser_create();
51$rss_parser = new RSSParser();
52xml_set_object($xml_parser,&$rss_parser);
53xml_set_element_handler($xml_parser, "startElement", "endElement");
54xml_set_character_data_handler($xml_parser, "characterData");
55$fp = fopen($filename,"r")
56 or die("Error reading RSS data.");
57while ($data = fread($fp, 4096))
58 xml_parse($xml_parser, $data, feof($fp))
59 or die(sprintf("XML error: %s at line %d",
60 xml_error_string(xml_get_error_code($xml_parser)),
61 xml_get_current_line_number($xml_parser)));
62fclose($fp);
63xml_parser_free($xml_parser);
64
65?>
This page took 0.095775 seconds and 4 git commands to generate.