note 41772 added to ref.xml

From: Date: Wed, 21 Apr 2004 22:51:07 +0000
Subject: note 41772 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-68491@lists.php.net to get a copy of this message
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; } } } } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41772 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41772&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41772&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68491) next »