note 41772 deleted from ref.xml by bjori
| From: | bjori@php.net | Date: | Mon, 09 Oct 2006 11:17:27 +0000 |
| Subject: | note 41772 deleted from ref.xml by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118305@lists.php.net to get a copy of this message | ||
Note Submitter: nate at adeptisoft dot com
----
just a slight modification to info at b1g dot de's wonderful RDFParse class... I have changed
"titel" to "title" and added the description.. so output should look like:
[1] => Array
(
[description] => Some story here
[title] => A title
[link] => http://www.urlofchoice.net/
)
-------
<?php
class RDFParser {
var $_item;
var $_url;
function RDFParser($url) {
$this->_url = $url;
}
function ParseRDF() {
$this->_item = array('i' => 0);
$parser = xml_parser_create();
xml_set_object($parser, &$this);
xml_set_element_handler($parser, "_startElement", "_endElement");
xml_set_character_data_handler($parser, "_charHandler");
$fp = fopen($this->_url, "r");
while(!feof($fp)) {
$line = fgets($fp, 4096);
xml_parse($parser, $line);
}
fclose($fp);
xml_parser_free($parser);
return($this->_item['items']);
}
function _startElement($parser, $name, $attrs) {
$this->_item['maychar'] = true;
if($name=="ITEM") {
$this->_item['mayparse'] = true;
$this->_item['i']++;
} elseif($name=="TITLE") {
$this->_item['akt'] = "TITLE";
} elseif($name=="LINK") {
$this->_item['akt'] = "LINK";
} elseif($name=="DESCRIPTION") {
$this->_item['akt'] = "DESCRIPTION";
} else {
$this->_item['maychar'] = false;
}
}
function _endElement($parser, $name) {
if($name=="ITEM") {
$this->_item['mayparse'] = false;
} elseif($name=="TITLE" || $name=="LINK" ||
$name="DESCRIPTION") {
$this->_item['maychar'] = false;
}
}
function _charHandler($parser, $data) {
if($this->_item['maychar'] && $this->_item['mayparse']) {
if($this->_item['akt']=="TITLE") {
$this->_item['items'][$this->_item['i']]['title']
= $data;
}
if($this->_item['akt']=="LINK") {
$this->_item['items'][$this->_item['i']]['link']
= $data;
}
if($this->_item['akt']=="DESCRIPTION") {
$this->_item['items'][$this->_item['i']]['description'] = $data;
}
}
}
}
?>