oracle765 Posted January 18, 2018 Share Posted January 18, 2018 I am trying to extract data from an API and not to sure where I am going wrong or even doing it correctly for that matter. Initally I cannot even print out the URL values Any help would be greatly appreciated professionals. here is my code, i know the url works in the browser address bar <?php $holidays_url="http://87.102.127.86:8103/search/searchoffers.dll?page=Resort&countryid=7"; $holidays_curl = curl_init(); curl_setopt($holidays_curl, CURLOPT_ENCODING, "gzip"); curl_setopt($holidays_curl, CURLOPT_URL, $holidays_url); curl_setopt($holidays_curl, CURLOPT_RETURNTRANSFER, true); $holidays_xml = new SimpleXMLElement(curl_exec($holidays_curl)); $holidays_date = DateTime::createFromFormat("Y-m-d", $startdate); $holidays_link=$holidays_xml; $holidays_stdclass=json_decode(json_encode($holidays_xml)); echo "<pre>"; print_r($holidays_xml); ?> Link to comment Share on other sites More sharing options...
phpmillion Posted January 18, 2018 Share Posted January 18, 2018 So what does the code output? Link to comment Share on other sites More sharing options...
oracle765 Posted January 19, 2018 Author Share Posted January 19, 2018 hi there nothing it is blank screen Link to comment Share on other sites More sharing options...
phpmillion Posted January 19, 2018 Share Posted January 19, 2018 Try to enable error reporting in your script, so you will see where the error is. I launched your code on my server and it displays "fatal error" Link to comment Share on other sites More sharing options...
oracle765 Posted January 19, 2018 Author Share Posted January 19, 2018 $holidays_url="http://87.102.127.86:8103/search/searchoffers.dll?page=Resort&countryid=7"; $holidays_curl = curl_init(); curl_setopt($holidays_curl, CURLOPT_ENCODING, "gzip"); curl_setopt($holidays_curl, CURLOPT_URL, $holidays_url); curl_setopt($holidays_curl, CURLOPT_RETURNTRANSFER, true); $holidays_xml = new SimpleXMLElement(curl_exec($holidays_curl)); $holidays_stdclass=json_decode(json_encode($holidays_xml)); error_reporting(E_ALL); ini_set("display_errors", 1); echo "<pre>"; print_r($holidays_stdclass); This still shows a blank screen Link to comment Share on other sites More sharing options...
phpmillion Posted January 19, 2018 Share Posted January 19, 2018 Is there a specific reason why you enable error reporting only after the code itself? Link to comment Share on other sites More sharing options...
oracle765 Posted January 19, 2018 Author Share Posted January 19, 2018 ah sorry never realised it had to be in front Link to comment Share on other sites More sharing options...
oracle765 Posted January 19, 2018 Author Share Posted January 19, 2018 ok i have this now ini_set("display_errors", 1); error_reporting(E_ALL); $holidays_url="http://87.102.127.86:8103/search/searchoffers.dll?page=Resort&countryid=7"; $holidays_curl = curl_init($holidays_url); curl_setopt($holidays_curl, CURLOPT_ENCODING, "gzip"); curl_setopt($holidays_curl, CURLOPT_URL, $holidays_url); curl_setopt($holidays_curl, CURLOPT_RETURNTRANSFER, true); //$holidays_xml = new SimpleXMLElement(curl_exec($holidays_curl)); $holidays_xml = new SimpleXMLElement(curl_exec($holidays_curl),null,true); //echo $feed->SHOPITEM[0]->ID_PRODUCT; $holidays_stdclass=json_decode(json_encode($holidays_xml)); echo "<pre>"; print_r($holidays_stdclass); i am getting error message SimpleXMLElement::__construct(): I/O warning : failed to load external entity "" in /home/ccuk/public_html/holiday-test.php on line 53Fatal error: Uncaught Exception: String could not be parsed Link to comment Share on other sites More sharing options...
phpmillion Posted January 19, 2018 Share Posted January 19, 2018 Alright, try to change: curl_setopt($holidays_curl, CURLOPT_RETURNTRANSFER, true); into: curl_setopt($holidays_curl, CURLOPT_RETURNTRANSFER, true); $debugme=curl_exec($holidays_curl); echo $debugme; exit(); What do you see? Hint: you may need to click CTRL + U to view the source code of the output because browser itself surely displays an empty page (because result is XML tags). Do you at least see some output returned? Link to comment Share on other sites More sharing options...
oracle765 Posted January 19, 2018 Author Share Posted January 19, 2018 I see no output still this is what i now have ini_set("display_errors", 1); error_reporting(E_ALL); $holidays_url="http://87.102.127.86:8103/search/searchoffers.dll?page=Resort&countryid=7"; $holidays_curl = curl_init($holidays_url); curl_setopt($holidays_curl, CURLOPT_ENCODING, "gzip"); curl_setopt($holidays_curl, CURLOPT_URL, $holidays_url); curl_setopt($holidays_curl, CURLOPT_RETURNTRANSFER, true); $debugme=curl_exec($holidays_curl); echo $debugme; exit(); //$holidays_xml = new SimpleXMLElement(curl_exec($holidays_curl)); $holidays_xml = new SimpleXMLElement(curl_exec($holidays_curl),null,true); $holidays_stdclass=json_decode(json_encode($holidays_xml)); echo "<pre>"; print_r($holidays_stdclass); and not even an error message now? i know when i click the url i can see results but can seem to extract info from it Link to comment Share on other sites More sharing options...
gizmola Posted January 19, 2018 Share Posted January 19, 2018 Please use code tags in your posts! You can do this in GUI mode, using the code button "" or use: [code] [/code] Link to comment Share on other sites More sharing options...
benanamen Posted January 19, 2018 Share Posted January 19, 2018 Here, start with something that gets the data. <?php function get_data($path){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$path); curl_setopt($ch, CURLOPT_FAILONERROR,1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); $retValue = curl_exec($ch); curl_close($ch); return $retValue; } $a = get_data('http://87.102.127.86:8103/search/searchoffers.dll?page=Resort&countryid=7'); $b = new SimpleXMLElement($a); echo "<pre>"; print_r($b); echo "</pre>"; Link to comment Share on other sites More sharing options...
oracle765 Posted January 20, 2018 Author Share Posted January 20, 2018 hi there I have tried that and get this error Fatal error: Uncaught Exception: String could not be parsed as XML in /home/ccuk/public_html/holiday-test.php:18 Stack trace: #0 /home/ccuk/public_html/holiday-test.php(18): SimpleXMLElement->__construct('') #1 {main} thrown in /home/ccuk/public_html/holiday-test.php on line 18 Link to comment Share on other sites More sharing options...
phpmillion Posted January 20, 2018 Share Posted January 20, 2018 benanamen's code works perfectly for me. If you don't see any output using my code too, I only have these ideas: 1. Your server can't connect to 87.102.127.86 for some reason such as invalid configuration in your end (you will need to find the reason on your own, however) 2. Your server has outgoing port 8103 blocked, so script can't parse data. 3. Your server is blocked by 87.102.127.86 administrator. In other words, your server can't parse data because it can't fetch data. Because exactly the same error will be displayed if you try to pass an empty string into SimpleXMLElement function. Link to comment Share on other sites More sharing options...
oracle765 Posted January 22, 2018 Author Share Posted January 22, 2018 ok update managed to get the port open and it works fine now... thanks for the advice Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.