waddledoo Posted December 12, 2011 Share Posted December 12, 2011 I am trying to get an XML file from a URL, but am instead getting errors. The code worked perfectly when executed on my own computer through a localhost server, but when executed through my webhost's server I get the errors. I am running PHP 5.3.8, and my webhost is running PHP 5.2.17, so I am assuming this may be an error between versions. $ch = curl_init($url); // Set the options for this request//This section returned a function not found error when activated on the webhost's server /*curl_setopt_array($ch, array( CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data CURLOPT_SSL_VERIFYPEER => false, // Do not verify the SSL certificate ));*/ // Fetch the data from the URL $data = curl_exec($ch); // Close the connection curl_close($ch); // Return a new SimpleXMLElement based upon the received data //The following is line 27 in the code if (!$xml = new SimpleXMLElement($data)) echo 'FAIL.'; Errors: Warning: Entity: line 1: parser error : Start tag expected, '<' not found in /home/(etc etc) on line 27 Warning: 1 in /home/(etc etc) on line 27 Warning: ^ in /home/(etc etc) on line 27 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/(etc etc):27 Stack trace: #0 /home/(etc etc)(27): SimpleXMLElement->__construct('1') #1 /home/(etc etc)(71): retrieveXMLdata() #2 {main} thrown in /home/(etc etc) on line 27 Link to comment https://forums.phpfreaks.com/topic/253015-xml-error/ Share on other sites More sharing options...
requinix Posted December 12, 2011 Share Posted December 12, 2011 What's the URL and/or the $data? Link to comment https://forums.phpfreaks.com/topic/253015-xml-error/#findComment-1297217 Share on other sites More sharing options...
waddledoo Posted December 12, 2011 Author Share Posted December 12, 2011 The URL contains the following: <api> <currentTime>2011-12-12 21:21:57</currentTime> <result> <rowset name="entries" key="refID" columns="date,refID,refTypeID,ownerName1,ownerID1,ownerName2,ownerID2,argName1,argID1,amount,balance,reason"> <row date="####-##-## ##:##:##" refID="#####" refTypeID="#####" ownerName1="#####" ownerID1="#####" ownerName2="#####" ownerID2="#####" argName1="#####" argID1="#####" amount="#####" balance="#####" reason="#####"/> <row date="####-##-## ##:##:##" refID="#####" refTypeID="#####" ownerName1="#####" ownerID1="#####" ownerName2="#####" ownerID2="#####" argName1="#####" argID1="#####" amount="#####" balance="#####" reason="#####"/> <row date="####-##-## ##:##:##" refID="#####" refTypeID="#####" ownerName1="#####" ownerID1="#####" ownerName2="#####" ownerID2="#####" argName1="#####" argID1="#####" amount="#####" balance="#####" reason="#####"/> (etc etc...) </rowset> </result> <cachedUntil>2011-12-12 21:48:57</cachedUntil> </api> Link to comment https://forums.phpfreaks.com/topic/253015-xml-error/#findComment-1297249 Share on other sites More sharing options...
requinix Posted December 12, 2011 Share Posted December 12, 2011 Ah, wait. Moot question. You need the RETURNTRANSFER setting. curl_setopt_array() is available on PHP 5.1.3+. If you can't use it then your host has an older version (!) and you need multiple calls to curl_setopt instead. Link to comment https://forums.phpfreaks.com/topic/253015-xml-error/#findComment-1297255 Share on other sites More sharing options...
waddledoo Posted December 12, 2011 Author Share Posted December 12, 2011 curl_setopt($ch,CURLOPT_FOLLOWLOCATION => true); curl_setopt($ch,CURLOPT_RETURNTRANSFER => true); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER => false); To that effect? EDIT: I get the error Parse error: parse error, unexpected T_DOUBLE_ARROW With the code. I changed the => to = with no effect. How do I properly use this function then? Second EDIT: I replaced the => with , (commas) ex/ curl_setopt($ch,CURLOPT_SSL_VERIFYPEER ,false); And I no longer get errors. My code still seems to not be running properly later in the program, and I am debugging now to find what is wrong. However, this particular post seems to be solved. Link to comment https://forums.phpfreaks.com/topic/253015-xml-error/#findComment-1297279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.