RaythMistwalker Posted January 6, 2010 Share Posted January 6, 2010 <Response> <Ip>127.0.0.1</Ip> <Status>OK</Status> <CountryCode>GB</CountryCode> <CountryName>United Kingdom</CountryName> <RegionCode>U8</RegionCode> <RegionName>Region</RegionName> <City>City</City> <ZipPostalCode/> <Latitude>Cords</Latitude> <Longitude>Cords</Longitude> <Timezone>0</Timezone> <Gmtoffset>0</Gmtoffset> <Dstoffset>1</Dstoffset> </Response> This gets info from http://www.ipinfodb.com/ip_query.php?ip=$ip&output=xml and i wish to save in an array called $ipinfo but still dunno howto use arrays in php and then get info from the xml file. I have: $ipinfo = file_get_contents("http://www.ipinfodb.com/ip_query.php?ip=$ip&output=xml"); from oni-kun and $ip is set at the beginning of the page working good. note: i don't need the IP to return from this page since i already have it. Any help is appreciated ~Rayth Quote Link to comment https://forums.phpfreaks.com/topic/187406-xml-to-array/ Share on other sites More sharing options...
CarbonCopy Posted January 6, 2010 Share Posted January 6, 2010 http://www.google.com/search?hl=en&q=php+xml+to+array Use Google next time please. Many examples that work fine on the first page Quote Link to comment https://forums.phpfreaks.com/topic/187406-xml-to-array/#findComment-989639 Share on other sites More sharing options...
salathe Posted January 6, 2010 Share Posted January 6, 2010 Why not use their JSON API to save you parsing and extracting the XML data into an array; you could then just use json_decode and voila an array (or object if you want). Change the API URL to use output=json instead of output=xml. Quote Link to comment https://forums.phpfreaks.com/topic/187406-xml-to-array/#findComment-989644 Share on other sites More sharing options...
RaythMistwalker Posted January 6, 2010 Author Share Posted January 6, 2010 erm what do i do about thse: Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /path/to/file/ipinfo.php on line 18 Warning: file_get_contents(http://www.ipinfodb.com/ip_query.php?ip=IPHERE&output=json) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /path/to/file/ipinfo.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/187406-xml-to-array/#findComment-989653 Share on other sites More sharing options...
salathe Posted January 6, 2010 Share Posted January 6, 2010 The error states that access to files using an URL is disabled in the config. Turn on (or set to 1) the allow_url_fopen setting in your php.ini (details). Were you not getting this error with the XML URL? Quote Link to comment https://forums.phpfreaks.com/topic/187406-xml-to-array/#findComment-989659 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.