I'm currently trying to query an API system (the return being XML), and everything works fine when I use file_get_contents with the URL:
http://bcoddsfeed.goldenpalace.be/getXML.php
However, after I find a game ID and add ?gameid=ID to the URL, I get a very odd error (which appears to prevent me from turning it into multi-level array by means of json_encode and json_decode). An example of the URL which does not work is:
http://bcoddsfeed.goldenpalace.be/getXML.php?gameid=1130733827
When I use var_dump on the data I've retrieved, I get it back in a somewhat mangled format with the following HTTP_USER_AGENT error at the beginning, which mucks things up.
Notice: Undefined index: HTTP_USER_AGENT in /usr/local/www/bcoddsfeed.goldenpalace.be/getXML.php on line 29
The full output looks something like:
string(6502) "
Notice: Undefined index: HTTP_USER_AGENT in /usr/local/www/bcoddsfeed.goldenpalace.be/getXML.php on line 29
2015-01-18 10:00:00Match ResultW24.6W11.81X3.2<_1X12X2>Double Chance1X1.13121.27X21.88Total Goals: Over/UnderTotal Goals Under | 5.51.01Total Goals Over | 5.511Total Goals: Over/UnderTotal Goals Under | 3.51.15Total Goals Over | 3.54.5Total Goals: Over/UnderTotal Goals Under | 14.95Total Goals Over | 11.12Total Goals: Over/UnderTotal Goals Under | 31.22Total Goals Over | 33.75Total Goals: Over/UnderTotal Goals Over | 21.82Total Goals Under | 21.88Total Goals: Over/UnderTotal Goals Under | 0.56.75Total Goals Over | 0.51.07Total Goals: Over/UnderTotal Goals Over | 4.510Total Goals: Over/UnderTotal Goals Under | 41.05Total Goals Over | 47.5Total Goals: Over/UnderTotal Goals Over | 1.51.45Total Goals Under | 1.52.5Total Goals: Over/UnderTotal Goals Under | 2.51.5Total Goals Over | 2.52.4Goals of Team 2Goals of Team 2 Over | 2.511Goals of Team 2 Under | 2.51.01Goals of Team 1Goals of Team 1 Under | 21.25Goals of Team 1 Over | 23.5Goals of Team 2Goals of Team 2 Over | 12.85Goals of Team 2 Under | 11.35Goals of Team 2Goals of Team 2 Over | 1.54.5Goals of Team 2 Under | 1.51.15Goals of Team 1Goals of Team 1 Under | 1.51.6Goals of Team 1 Over | 1.52.15Goals of Team 1Goals of Team 1 Over | 11.45Goals of Team 1 Under | 12.5Goals of Team 1Goals of Team 1 Under | 2.51.15Goals of Team 1 Over | 2.54.5Asian HandicapAsian Handicap 2 | 2.51.05Asian Handicap 1 | -2.57.5Asian HandicapAsian Handicap 2 | 1.51.27Asian Handicap 1 | -1.53.3Asian HandicapAsian Handicap 1 | -25.5Asian Handicap 2 | 21.1Asian HandicapAsian Handicap 2 | 11.45Asian Handicap 1 | -12.5Asian HandicapAsian Handicap 2 | 03.05Asian Handicap 1 | 01.32Correct Score2:07.41:05.20:2231:2161:41602:41806:02105:1955:21902:193:014.53:118.53:2420:071:16.42:2210:19.46:1211:3500:3653:31002:3604:1404:0344:31804:2900:41804:42303:42705:075"
Does anyone have any ideas on how to fix this HTTP_USER_AGENT mishap and get a nice clean xml string which I can convert into a .json for use in my php application? I'm very unexperienced with this, and any help would be greatly appreciated since I am totally lost.
I don't see this error when I visit the link with my browser, so I'm not sure what's going on.
Thank you!
I've also tried using the curl function below to call in the data via the URL, but no luck. I still get the same error.
CURL FUNCTION
public static function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}