intodesi Posted April 25, 2008 Share Posted April 25, 2008 I am trying to use this class, yet when i load the page I get this Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/techurch/public_html/zinto/pages/scripts/XMLParser.class.php on line 20 here is the class class SimpleXmlParser { public # Variable Holding Parser $SimpleParser = null, $feedUrl = null, # Variables to Hold the Data $title = '', $description = '', $link = '', $author = '', $pubDate = '', $insideitem = false, $tag = ''; public function __construct($MyFeed) { # To begin, I create an instance of the XML parser # creates a new XML parser and returns a reousurce handle referencing $this->SimpleParser = xml_parser_create(); # Assigns the Feed Source to the Member Variable $this->feedUrl = $MyFeed; # allows to use parser inside object xml_set_object($this->SimpleParser, $this); # Sets the element handler functions for the XML parser parser xml_set_element_handler($this->SimpleParser, 'XmlParserFirstElement', 'XmlParserendElement'); # Sets the character data handler function for the XML parser parser xml_set_character_data_handler($this->SimpleParser, 'characterData'); # Call to Parser Function $this->ParseFeed(); } public function SimpleXmlParser($MyFeed) { # Purpose : Constructor, Which will initialize the XML Parser $this->__construct($MyFeed); } public function XmlParserFirstElement($parser, $tagName, $attrs) { # The Function Will be called, when ever the XML_PARSER Encounters a start Tag, in the XML File if ($this->insideitem) { $this->tag = $tagName; } elseif (strtoupper($tagName)=='ITEM') { $this->insideitem = true; } } public function XmlParserendElement($parser, $tagName) { # The Function Will be called, when ever the XML_PARSER Encounters a end Tag, in the XML File if (strtoupper($tagName)=='ITEM') { # pubDate element is made to display in HTML printf("<div style='padding:5px;'><div class='news_date'>%s</div>", date("m.d.Y",strtotime($this->pubdate))); # Description element is made to display in HTML printf("<div ><a class='news_text' href='%s' target='new'>%s</a><br /></div><div style='clear:both'></div></div>", trim($this->link), htmlspecialchars(trim($this->title))); # Deallocation of all Global Variables $this->title = ''; $this->description = ''; $this->link = ''; $this->pubdate = ''; $this->insideitem = false; } } # Function will be called by the Parser when the end tage of the element is processed. Requires Two Permeters public function characterData($parser, $data) { # Permeters: the parser instance and the string containing the data. if ($this->insideitem) { switch (strtoupper($this->tag)) { case 'TITLE': $this->title .= $data; break; case 'DESCRIPTION': $this->description .= $data; break; case 'LINK': $this->link .= $data; break; case 'PUBDATE': $this->pubdate .= $data; break; } } } public function ParseFeed(){ # This is the Place we need to Do error Handling for the XML file, which is not done in this class # Open the XML file for reading. # This part will be executed when we compiler is Unable to Open the XML Feed $fp = fopen($this->feedUrl, 'r') or die('Oops! Unexpected Error While Reading the Feed'); # Starts reading the contents of the file, 4K at a time, and put it in the variable “$data” while ($data = fread($fp, 4096)) { xml_parse($this->SimpleParser, $data, feof($fp)); } # Perform Some Clean Up Work Before Closing the File. # Closing the XML File fclose($fp); # Release the XML Parser xml_parser_free($this->SimpleParser); } } Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/102956-solved-xml-parser-class/ Share on other sites More sharing options...
dptr1988 Posted April 25, 2008 Share Posted April 25, 2008 Where is line 20 in this example you posted? Quote Link to comment https://forums.phpfreaks.com/topic/102956-solved-xml-parser-class/#findComment-527417 Share on other sites More sharing options...
Daniel0 Posted April 25, 2008 Share Posted April 25, 2008 Any reason why you cannot use SimpleXML which comes with PHP? Quote Link to comment https://forums.phpfreaks.com/topic/102956-solved-xml-parser-class/#findComment-527421 Share on other sites More sharing options...
intodesi Posted April 25, 2008 Author Share Posted April 25, 2008 sorry, line 20 would be in red class SimpleXmlParser { public # Variable Holding Parser $SimpleParser = null, $feedUrl = null, # Variables to Hold the Data $title = '', $description = '', $link = '', $author = '', $pubDate = '', $insideitem = false, $tag = ''; and I will try the simplexml thanks (will that parse offsite rss feeds? thats my goal) Quote Link to comment https://forums.phpfreaks.com/topic/102956-solved-xml-parser-class/#findComment-527427 Share on other sites More sharing options...
Daniel0 Posted April 25, 2008 Share Posted April 25, 2008 It will parse any well-formed XML document, so yes. Quote Link to comment https://forums.phpfreaks.com/topic/102956-solved-xml-parser-class/#findComment-527431 Share on other sites More sharing options...
intodesi Posted April 25, 2008 Author Share Posted April 25, 2008 ok figured out maybe why I cant use that, my hosting is doing php 4.3 SimpleXML is a component of php 5 (unless i read wrong ) Quote Link to comment https://forums.phpfreaks.com/topic/102956-solved-xml-parser-class/#findComment-527437 Share on other sites More sharing options...
intodesi Posted April 25, 2008 Author Share Posted April 25, 2008 Found me a perfect solution with lastRSS thanks for help Quote Link to comment https://forums.phpfreaks.com/topic/102956-solved-xml-parser-class/#findComment-527461 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.