R3p1v Posted November 10, 2007 Share Posted November 10, 2007 I just upgraded PHP from version 4 to 5 and this parser stopped working. Can someone help me fix it please? Thanks! (I replaced sensitive data with "REMOVED") <?php class XMLParser { var $filename; var $xml; var $data; function XMLParser($xml_file) { $this->filename = $xml_file; $this->xml = xml_parser_create(); xml_set_object($this->xml, $this); xml_set_element_handler($this->xml, 'startHandler', 'endHandler'); xml_set_character_data_handler($this->xml, 'dataHandler'); $this->parse($xml_file); } function parse($xml_file) { $feed = "$xml_file"; $ch = curl_init($feed); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, "http://REMOVED"); $fp = trim(curl_exec($ch)); curl_close($ch); if (!$fp) { die('Cannot open XML data file: '.$xml_file); return false; } $bytes_to_parse = 512; $parse = xml_parse($this->xml, $fp); if (!$parse) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->xml)), xml_get_current_line_number($this->xml))); xml_parser_free($this->xml ); } return true; } function startHandler($parser, $name, $attributes) { $data['name'] = $name; if ($attributes) { $data['attributes'] = $attributes; } $this->data[] = $data; } function dataHandler($parser, $data) { if ($data = trim($data)) { $index = count($this->data) - 1; // begin multi-line bug fix (use the .= operator) $this->data[$index]['content'] .= $data; // end multi-line bug fix } } function endHandler($parser, $name) { if (count($this->data) > 1) { $data = array_pop($this->data); $index = count($this->data) - 1; $this->data[$index]['child'][] = $data; } } } $url = "REMOVED"; $myFile = new XMLParser($url); $data = $myFile->data; /////Variables assigned here, removed////// ?> Quote Link to comment Share on other sites More sharing options...
R3p1v Posted November 10, 2007 Author Share Posted November 10, 2007 It isn't working and returns the error: "Cannot open XML data file: XXXXXX" Quote Link to comment Share on other sites More sharing options...
R3p1v Posted November 10, 2007 Author Share Posted November 10, 2007 Sorry to keep bumping this =/ I need to get this solved quick though. Since its displaying that error, I guess the problem is in these few lines. Why is this on working on PHP 5? function parse($xml_file) { $feed = "$xml_file"; $ch = curl_init($feed); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, "http://REMOVED"); $fp = trim(curl_exec($ch)); curl_close($ch); if (!$fp) { die('Cannot open XML data file: '.$xml_file); return false; } Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 10, 2007 Share Posted November 10, 2007 Try changing those lines to this <?php function parse($xml_file) { $feed = trim($xml_file); $ch = curl_init($feed); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, "http://REMOVED"); $fp = curl_exec($ch); curl_close($ch); if (!$fp) { die('Cannot open XML data file: '.$xml_file); return false; } ?> Quote Link to comment Share on other sites More sharing options...
R3p1v Posted November 10, 2007 Author Share Posted November 10, 2007 That didn't seem to fix it I tried removing the trim completely and it didnt make any difference. Here is my phpinfo if you want to take a look at it: http://xboxlc.com/phpinfo.php Quote Link to comment Share on other sites More sharing options...
R3p1v Posted November 10, 2007 Author Share Posted November 10, 2007 hmm, I fixed it somehow by replacing it with very similar code. Not sure why that worked though. Thanks for the help anyway, I really appreciate it Quote Link to comment 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.