I have this news feed I got from somewhere I while ago and I am trying to change it.
I am a total newby when it comes to php and xml, but a database is not an option.
If I want to have the news title and a link for "more" to see the rest of the news a link, how would I do it.
The syntax is confusing me...here's my php code...
<?php
class newsboy {
var $xml_parser;
var $xml_file;
var $html;
var $open_tag;
var $close_tag;
//Class Constructor
function newsboy() {
$this->xml_parser = "";
$this->xml_file = "";
$this->html = "";
$this->open_tag = array("NEWSBOY" => "\n<!-- XML Starts here -->\n<TABLE COLS=1 CELLPADDING=5>",
"STORY" => "<TR><TD BGCOLOR=#222222>",
"SLUG" => "<FONT COLOR=#DAA520><B>",
"TEXT" => "</B><FONT COLOR=#FFFFFF>",
"MORE" => "<FONT COLOR=#DAA520>",
"NEWLINE" => "");
$this->close_tag = array("NEWSBOY" => "</TABLE>\n<!-- XML Ends here -->\n\n",
"STORY" => "</TD></TR>",
"SLUG" => "<FONT><BR>",
"TEXT" => "<FONT>\n",
"MORE" => "<FONT>",
"NEWLINE" => "<BR>");
}
//Class Descructor (has to be invoked manually as PHP does not support desctructors)
function destroy() {
xml_parser_free($this->xml_parser);
}
//Class Members
function concat($str) {
$this->html .= $str;
}
function startElement($parser, $name, $attrs) {
//global $open_tag;
if ($format= $this->open_tag[$name]) {
$this->html .= $format;
}
}
function endElement($parser, $name) {
global $close_tag;
if ($format= $this->close_tag[$name]) {
$this->html .= $format;
}
}
function characterData($parser, $data) {
$this->html .= $data;
}
function parse() {
$this->xml_parser = xml_parser_create();
xml_set_object($this->xml_parser, $this);
xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($this->xml_parser, "startElement", "endElement");
xml_set_character_data_handler($this->xml_parser, "characterData");
if(!($fp = fopen($this->xml_file, "r"))) {
die("could not open XML input");
}
while($data = fread($fp, 4096)) {
if (!xml_parse($this->xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->xml_parser)), xml_get_current_line_number($this->xml_parser)));
}
}
}
}
?>
I understand some of it, but have been trying to learn what it's all doing.
Also, does anyone know of a good book or any other reference for php and xml or is this justa self tought thing?
Thanks,
John