/ Published in: PHP
Expand |
Embed | Plain Text
<?php //alternative solution to this method was to use functions with globals variables! //define the class reference class rss_parser { //decare variables to be used inside class var $insideitem = false; var $tag = ""; var $title = ""; var $description = ""; var $link = ""; var $tags = ""; //functions to make our class do something! function start_tag($parser, $tagName, $attrs) { if ($this->insideitem) { $this->tag = $tagName; } elseif ($tagName == "DATACONTENT") { $this->insideitem = true; } $this->tags .= "<br />".$tagName; } function end_tag($parser, $tagName) { if ($tagName == "DATACONTENT") { //output a formatted string with placeholders! //empty vars $this->title = ""; $this->description = ""; $this->link = ""; $this->insideitem = false; } } function tag_data($parser, $data) { if ($this->insideitem) { switch ($this->tag) { case "HL1": $this->title .= $data; break; case "P": $this->description .= "<p>".$data."</p>"; break; case "A": $this->description .= "<a href=''>".$data."</a>"; break; } } } } //create xml parser //create the class object $rss_parser = new rss_parser(); //This function allows to use parser inside object //open xml file //read 4kb of the file at a time } //close file and delete parser //echo $rss_parser->tags; ?>
You need to login to post a comment.
